Part Number Hot Search : 
MC4741C AX1212 HP8KA1 K9F1G0 IRF9620 1N4753A SMB5923B MB87032P
Product Description
Full Text Search
 

To Download ZSP Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
 USER'S GUIDE
ZSPTM SDK Software Development Kit
April 2002 Revision 4.0
(R)
This document contains proprietary information of LSI Logic Corporation. The information contained herein is not to be used by or disclosed to third parties without the express written permission of an officer of LSI Logic Corporation. DB15-000126-06, Third Edition (April 2002) This document describes Rev. 4.0 of LSI Logic Corporation's ZSPTM SDK Software Development Kit and will remain the official reference source for all revisions/releases of this product until rescinded by an update. LSI Logic Corporation reserves the right to make changes to any products herein at any time without notice. LSI Logic does not assume any responsibility or liability arising out of the application or use of any product described herein, except as expressly agreed to in writing by LSI Logic; nor does the purchase or use of a product from LSI Logic convey a license under any patent rights, copyrights, trademark rights, or any other of the intellectual property rights of LSI Logic or third parties. Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved. TRADEMARK ACKNOWLEDGMENT The LSI Logic logo design and ZSP are trademarks or registered trademarks of LSI Logic Corporation. Microsoft, Microsoft Access, MS-DOS, Windows, and Windows NT are registered trademarks of Microsoft Corporation. UNIX is a registered trademark of X/Open Company, Ltd. Solaris is a trademark of Sun Microsystems, Inc. All other brand and product names may be trademarks of their respective companies. For a current list of our distributors, sales offices, and design resource centers, view our web page located at http://www.lsilogic.com/contacts/na_salesoffices.html
ii
Preface
This book is the primary reference and user's guide for the ZSPTM SDK Software Development Kit. The SDK supports digital signal processors based on the ZSP400 core (for example, the LSI402ZX and LSI403Z) and the next generation ZSP G2 architecture.
Audience This document assumes that you have some familiarity with the C language, and with the ZSP architecture and assembly language. Those who will benefit from this book are
* * *
Engineers and managers who are evaluating the ZSP processor for possible use in a system Engineers who are designing products based on the ZSP architecture and wish to perform cost and performance analysis Engineers who are developing software for systems based on the ZSP architecture
Organization This document has the following chapters and appendices:
* * * * *
Chapter 1, Introduction, introduces the ZSP SDK software development kit. Chapter 2, Installation, describes how to install the SDK. Chapter 3, C Cross Compiler, describes the SDK C compiler. Chapter 4, Assembler, describes the assembler in the SDK tool set. Chapter 5, Linker, describes the linker in the SDK tool set.
Preface
iii
* * * * *
Chapter 6, Utilities, describes miscellaneous utilities in the SDK tool set. Chapter 7, ZISIM Simulator, describes the SDK functional-accurate simulator. Chapter 8, ZSIM Simulator, describes the SDK cycle-accurate simulator. Chapter 9, Debugger, describes the SDK debugger. Chapter 10, ZSP Integrated Development Environment (ZSP IDE), describes the SDK Project Manager provided by LSI Logic with Windows 95/98/NT versions of the SDK. Chapter 11, ZSP IDE Debugger, describes the GUI Debugger provided by LSI Logic with Windows 95/98/NT versions of the SDK. Appendix A, Example Programs, provides a sample program for use with the SDK. Appendix B, ZSP400 Control Registers, lists the ZSP400 control registers. Appendix C, ZSPG2 Control Registers, lists the ZSPG2 control registers. Appendix D, L-Intrinsic Functions, describes the L-Intrinsic functions supported by the SDK compiler. Appendix E, Signal Processing Library, describes the libalg.a library.
* * * * * *
Related Publications LSI402ZX Digital Signal Processor User's Guide, LSI Logic Corporation, order number R14021. Provides detailed information on the LSI402ZX Digital Signal Processor. LSI403Z Digital Signal Processor User's Guide, LSI Logic Corporation, order number R14025. Provides detailed information of the LSI403Z digital Signal Processor. ZSP400 Digital Signal Processor Architecture Technical Manual, LSI Logic Corporation, order number I14036. Provides detailed information on the registers and instruction set defined by the ZSP architecture and implemented in the LSI4xx family of processors.
iv
Preface
Using and Porting GNU CC, by Richard M. Stallman, Free Software Foundation, June 1996. Provides detailed information on how to use GCC, which is the foundation of SDCC. Using AS: The GNU Assembler, by Dean Elsner, et. al., Free Software Foundation, January 1994. Provides detailed information on how to use AS, which is the foundation of SDAS. Using LD: The GNU Linker, by Steve Chamberlain, Free Software Foundation, January 1994. Provides detailed information on how to use LD, which is the foundation of SDLD. Debugging with GDB: The GNU Source Level Debugger, by Richard Stallman, et. al., Free Software Foundation, January 1994. Provides detailed information on how to use GDB, which is the foundation of SDBUG. EB402 Evaluation Board Getting Started, LSI Logic Corporation, order number DBO6-000264-01, September, 2000. Provides information on using the EB402 Evaluation Board. EB402 Evaluation Board User's Guide, LSI Logic Corporation, order number DB15-000143-00, September, 2000. Provides detailed information on how to use the EB402 Evaluation Board. PCMCIA-1149.1 Windows 95/NT Software Development Kit User's Guide, Corelis, Inc. Provides detailed information on using the JTAG interface. Man pages for ar, nm, objdump, string, size, objcopy, strip and ranlib from the Free Software Foundation, available from the FTP site prep.ai.mit.edu.
Conventions Used in This Manual The first time a word or phrase is defined in this manual, it may be italicized. Hexadecimal numbers are indicated by the prefix "0x", for example, 0x32CF. Binary numbers are indicated by the prefix "0b", for example, 0b0011.0010.1100.1111.
Preface
v
The term `DOS', unless otherwise noted, includes the MS-DOS operating system and its Windows 3.1, Windows 95, Windows 98, and Windows NT supersets. The term `PC', unless otherwise noted, includes the 386-, the 486-, and the Pentium-based IBM-PC or compatible host computers. Additional notational conventions used throughout this manual are listed below.
Notation courier typeface bold typeface Example .nwk file fd1sp Meaning and Use Names of commands, files, directories, and code are shown in courier typeface In a command line, command keywords are shown in bold, nonitalic courier typeface. Enter them exactly as shown, including case. In command lines and syntax descriptions, italics indicate user-defined variables of a type defined by the italicized noun. Italicized text must be replaced with appropriate user-specified items. When an underscore appears in an italicized string, enter a user-supplied item of the type called for, without spaces.
italics
module
italic underscore
full_pathname
brackets
[ version ] In command formats, you may, but need not, enter an [ filename | register ] item enclosed within brackets. When vertical bars are used within brackets, you may select one (but not more than one) of the items separated by bars. Do not enter the brackets or bar. { directory } In command formats, you must select one (but not { filename | register } more than one) item enclosed within braces. Do not enter the braces. When vertical bars are used within braces, you may select one (but not more than one) of the items separated by braces. Do not enter the braces or bar. option... In command formats, elements preceding ellipses may be repeated any number of times. Do not enter the ellipses. In menu items, if an ellipsis appears after an item, clicking that item brings up a dialog box.
braces
ellipses
vi
Preface
Notation vertical dots
Example . . . ;
Meaning and Use Vertical dots indicate that a portion of a program or listing has been omitted from the text. Use as shown in the text.
semicolon, and other punctuation
Preface
vii
viii
Preface
Contents
Chapter 1 Introduction 1.1 1.2 Chapter 2 Installation 2.1 2.2 Contents of the CD-ROM Installation on Windows Systems 2.2.1 Installing SDK Tools 2.2.2 Restarting Windows Uninstalling the SDK Tools on Windows Systems Installation on Solaris Systems 2-1 2-1 2-2 2-9 2-9 2-10 Overview of the SDK Tools Overview of Software Development Using the SDK Tools 1-2 1-5
2.3 2.4 Chapter 3 C Cross Compiler 3.1 3.2
3.3 3.4 3.5
Compiler Options 3-2 Compiler Conventions 3-4 3.2.1 Data Type Conventions 3-5 3.2.2 Register Usage 3-6 3.2.3 Conventions Used for Passing Parameters 3-9 3.2.4 Run Time Stack 3-10 3.2.5 Example Code for Function Prologue and Epilogue 3-11 3.2.6 Parameter Passing Examples 3-13 Run Time Environment 3-15 C Run Time Library Functions 3-15 N-Intrinsics 3-16 3.5.1 Vector N-Intrinsics 3-18 3.5.2 ETSI Functions 3-18
Contents
ix
3.6 3.7 3.8 3.9
3.10 3.11 3.12 3.13
Circular Buffers Accessing Control Registers Q15 Support Inline Assembly 3.9.1 Syntax 3.9.2 Parameterized Assembly 3.9.3 Variables and Expressions 3.9.4 Explicitly Clobbered Registers 3.9.5 Examples of asm Directive 3.9.6 Optimization of Inline Assembly Assembly Optimizer and Handwritten Assembly Debugging Options Code Statistics Example Compilations 3.13.1 Example 1 3.13.2 Example 2 3.13.3 Example 3 3.13.4 Example 4
3-20 3-21 3-22 3-23 3-23 3-23 3-24 3-25 3-25 3-28 3-28 3-29 3-29 3-30 3-30 3-30 3-30 3-30
Chapter 4 Assembler 4.1 Assembly Language Syntax 4.1.1 Assembler Options 4.1.2 Assembler Directives 4.1.3 Assembler Special Cases 4-1 4-2 4-3 4-4
Chapter 5 Linker 5.1 Sections 5.1.1 Symbols 5.1.2 Linker command file 5.1.3 Linker options 5-1 5-2 5-3 5-3
Chapter 6 Utilities 6.1 6.2 sdar sdstrip 6-2 6-5
x
Contents
6.3 6.4 6.5 6.6 6.7 6.8 Chapter 7 ZISIM Simulator 7.1
sdranlib sdnm sdsize sdstrings sdobjdump sdobjcopy
6-7 6-8 6-9 6-11 6-12 6-14
7.2
Using ZISIM 7.1.1 Batch Mode 7.1.2 Interactive Mode ZISIM Commands 7.2.1 alias 7.2.2 clear break 7.2.3 clear dmem 7.2.4 clear imem 7.2.5 clear stats 7.2.6 disable break 7.2.7 disable trace 7.2.8 dump dmem 7.2.9 dump imem 7.2.10 enable break 7.2.11 enable trace 7.2.12 exit 7.2.13 fill dmem 7.2.14 fill imem 7.2.15 help 7.2.16 load dmem 7.2.17 load exe 7.2.18 load imem 7.2.19 reset 7.2.20 run 7.2.21 script 7.2.22 set attr 7.2.23 set break 7.2.24 set reg
7-1 7-1 7-2 7-4 7-7 7-8 7-8 7-8 7-9 7-9 7-9 7-9 7-10 7-11 7-11 7-11 7-12 7-12 7-12 7-13 7-13 7-14 7-14 7-15 7-15 7-16 7-17 7-17
Contents
xi
7.3 7.4 Chapter 8 ZSIM Simulator 8.1
7.2.25 set size 7.2.26 show attr 7.2.27 show bits 7.2.28 show break 7.2.29 show dmem 7.2.30 show imem 7.2.31 show reg 7.2.32 show size 7.2.33 show stats 7.2.34 show trace 7.2.35 step 7.2.36 unalias I/O Port Usage Example Session Using ZISIM
7-17 7-18 7-19 7-19 7-20 7-20 7-21 7-22 7-22 7-23 7-23 7-23 7-24 7-24
8.2
Using ZSIM 8.1.1 Batch Mode 8.1.2 Interactive Mode ZSIM Commands 8.2.1 alias 8.2.2 clear break 8.2.3 clear dcache 8.2.4 clear dmem 8.2.5 clear icache 8.2.6 clear imem 8.2.7 clear stats 8.2.8 disable break 8.2.9 disable profile 8.2.10 disable trace 8.2.11 dump dmem 8.2.12 dump imem 8.2.13 enable break 8.2.14 enable profile 8.2.15 enable trace 8.2.16 exit
8-1 8-1 8-2 8-5 8-11 8-11 8-11 8-12 8-12 8-12 8-13 8-13 8-13 8-14 8-14 8-14 8-15 8-15 8-16 8-17
xii
Contents
8.3 8.4
8.2.17 fill dmem 8.2.18 fill imem 8.2.19 help 8.2.20 istep 8.2.21 load dmem 8.2.22 load exe 8.2.23 load imem 8.2.24 reset 8.2.25 run 8.2.26 script 8.2.27 set attr 8.2.28 set break 8.2.29 set delay 8.2.30 set latency 8.2.31 set reg 8.2.32 set size 8.2.33 show attr 8.2.34 show bits 8.2.35 show break 8.2.36 show dcache 8.2.37 show dmem 8.2.38 show icache 8.2.39 show imem 8.2.40 show pipe 8.2.41 show profile 8.2.42 show reg 8.2.43 show rule 8.2.44 show size 8.2.45 show stats 8.2.46 show trace 8.2.47 step 8.2.48 unalias I/O Port Usage Example Session Using ZSIM
8-17 8-17 8-18 8-18 8-19 8-19 8-20 8-20 8-21 8-21 8-22 8-23 8-23 8-24 8-24 8-24 8-25 8-26 8-26 8-26 8-28 8-28 8-29 8-29 8-30 8-30 8-31 8-31 8-32 8-32 8-32 8-33 8-33 8-34
Contents
xiii
Chapter 9 Debugger 9.1 9.2 Using SDBUG SDBUG Execution Environments 9.2.1 Functional-Accurate Simulator Connection 9.2.2 Cycle-Accurate Simulator Connection 9.2.3 UART Connection 9.2.4 JTAG Controller Connection Debugger Commands - Special Cases 9.3.1 Generic Target-Specific Commands 9.3.2 Backtrace Command 9.3.3 Info Registers Command 9.3.4 Breakpoint Command 9.3.5 Print Command 9.3.6 Set Command 9.3.7 Cycle-Step Command 9.3.8 Accessing Memory with the Debugger Dynamic Breakpoints Example Debugging Sessions 9.5.1 Example 1 9.5.2 Example 2 9-1 9-3 9-3 9-4 9-7 9-8 9-11 9-11 9-11 9-12 9-12 9-12 9-12 9-13 9-13 9-15 9-15 9-16 9-19
9.3
9.4 9.5
Chapter 10 ZSP Integrated Development Environment (ZSP IDE) 10.1 ZSP IDE Overview 10.1.1 Introduction to Workspaces and Projects 10.2 Working With Workspaces and Projects 10.2.1 Working With Workspaces 10.2.2 Working With Projects 10.3 Project Settings 10.3.1 Build methodology and Project Tree Structure 10.3.2 Compiler/Assembler Settings 10.3.3 Linker Settings 10.4 ZSP IDE Detailed Description 10.4.1 Paned Window Controls 10.4.2 Project Tree 10.4.3 Main Menu
10-2 10-2 10-4 10-4 10-7 10-9 10-10 10-10 10-14 10-17 10-17 10-17 10-19
xiv
Contents
10.4.4 Toolbar 10.5 Shell Window 10.6 Disassembly Window 10.7 Parallel Debug Manager 10.8 Help Menu 10.9 Editor 10.10 ZSP IDE File Formats Chapter 11 ZSP IDE Debugger 11.1 GUI Debugger Overview 11.1.1 Main Window 11.1.2 Title Bar - Project File Name Display 11.1.3 Window Area 11.1.4 Status Area 11.1.5 Main Menu 11.1.6 Main Toolbars 11.1.7 Debugging Windows (General) Detailed Descriptions 11.2.1 Main Menu 11.2.2 Debugging Window Detailed Descriptions
10-29 10-32 10-33 10-33 10-34 10-34 10-35
11.2
11-3 11-3 11-3 11-3 11-3 11-3 11-4 11-6 11-11 11-11 11-19
Appendix A Example Programs A.1 A.2
Example Program: demo.c Example Program hw_dbg.s
A-1 A-5
Appendix B ZSP400 Control Registers Appendix C ZSPG2 Control Registers Appendix D L-Intrinsic Functions
Contents
xv
Appendix E Signal Processing Library E.1 API Specification Auto-correlation Library Function on G2 E-2 E.1.1 Auto-correlation E-2 E.2 API Specification for Convolutional Encoder Library Function on G2 E-3 E.2.1 Convolutional Encoder E-3 E.3 API Specification for 16bit CRC Library Function on G2 E-5 E.3.1 CRC 16bit E-5 E.4 API Specification for 8bit CRC Library Function on G2 E-6 E.4.1 CRC 8bit E-6 E.5 API Specification for 32 bit Division Library Function on G2 E-7 E.5.1 32 bit Division E-7 E.6 API Specification for IIR Library Function on G2 E-8 E.6.1 IIR E-8 E.7 API Specification for IIR Biquad Library Function on G2 E-9 E.7.1 IIR Biquad E-9 E.8 API Specification for Inverse Square Root Library Function on G2 E-10 E.8.1 Inverse Square Root E-10 E.9 API Specification for Synthesis Lattice Filter Library Function on G2 E-11 E.9.1 Synthesis Lattice Filter E-11 E.10 API Specification for Real Block FIR Library Function on G2 E-12 E.10.1 Real Block FIR E-12 E.11 API Specification for 256 point FFT Library Function on G2 E-14 E.11.1 256 point FFT E-14 Index Customer Feedback
xvi
Contents
Figures 1.1 9.1 9.2 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11 10.12 10.13 10.14 10.15 10.16 10.17 10.18 10.19 10.20 10.21 10.22 10.23 10.24 10.25 10.26 10.27 10.28 11.1 11.2 11.3 11.4 11.5 Overview of Software Development Debugger Memory Addressing (sdbug400, zdxbug) Debugger Memory Addressing (zdbug) ZSP IDE Tools Suite Implementation ZSP IDE Workspace ZSP IDE Main Window Recent Workspaces List File Selection Dialog Project Menu Compiler Settings Assembler Settings Paned Window Handles ZSP IDE Project Tree ZSP IDE File Menu ZSP IDE Edit Menu ZSP IDE View Menu Customize Toolbar ZSP IDE Project Menu ZSP IDE Workspace Menu ZSP IDE Build Menu Build / Compile Output Window Build Output Window Popup Menu ZSP IDE Debug Menu Debug Settings Debug Window Settings Object File Utility Utility Output Window Showing Disassembled Code Shell Window Disassembly Window Parallel Debug Manager Setup Window Parallel Debug Manager Control Window Menu Checkmarks For Debugging Windows Tools Menu - Invoke Toolbars Preferences - Use Images For Toolbar Buttons Toolbar Buttons With Text Annotation Toolbar Buttons With Image Annotation 1-6 9-14 9-15 10-2 10-2 10-3 10-5 10-5 10-8 10-12 10-12 10-17 10-17 10-20 10-21 10-21 10-23 10-23 10-24 10-24 10-25 10-25 10-26 10-27 10-27 10-29 10-29 10-32 10-33 10-33 10-34 11-4 11-5 11-5 11-6 11-6
xvii
11.6 11.7 11.8 11.9 11.10 11.11 11.12 11.13 11.14 11.15 11.16 11.17 11.18 11.19 11.20 11.21 11.22 11.23 11.24 11.25 11.26 11.27 11.28 11.29 11.30 11.31 11.32 11.33 11.34 11.35 11.36 11.37 11.38 11.39 11.40 11.41 11.42 11.43
Debugger Paned Window 11-7 Paned Window Handles 11-8 Preferences - Set Main Window Columns 11-8 Top Level Debugging Window 11-9 Top Level Window Focus Control 11-9 Preferences - Separate New Window 11-9 Display Controls for Paned Window 11-10 Display Controls for Top Level Window 11-10 Preferences - Autoload Windows 11-10 Breakpoint Menu 11-12 Source Code Window Current Selection Line 11-12 Source Code Window Breakpoints 11-13 Execute Menu 11-15 Program View Menu 11-18 Target View Menu 11-18 Tools Menu 11-19 Source Code Window 11-20 Progress Bar Window 11-21 Source Code Window (shown with Disassembly Window) 11-21 Example Source Code Popup Query Result 11-22 Breakpoint List Window 11-23 Debugging Symbols Window 11-24 Call Stack Window 11-24 Local Variables Window 11-25 Global Variables Window 11-25 .Expression Window 11-26 Watch Expressions Window 11-26 ZSIM Profile Window 11-27 ZSIM Statistics Window 11-27 Disassembly Window 11-28 Register Element Popup Format Menu 11-29 Register Window Format Menu 11-29 Register Window Columns Menu 11-30 Register Window Configure Menu 11-30 Control Register Window - Standard Mode 11-30 Control Register Bitfield Entry Annotation 11-31 Control Register Window - Bitfield Mode 11-31 Operand Register Window 11-32
xviii
11.44 11.45 11.46 11.47 11.48 11.49 11.50 11.51
Address Register Window Memory Window ZSIM Grouping Rule Window ZSIM Pipeline Window Command Line Window Preferences Window - Logging Tools Menu - Session Log File Session Log Window
11-32 11-32 11-33 11-33 11-34 11-34 11-35 11-35
xix
xx
Tables 1.1 1.2 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 8.1 8.2 8.3 8.4 8.5 SDK Tools and GNU Counterparts SDK Utilities and GNU Counterparts Compiler Options Output Options Optimization Options Compiler's Representation of C Data Types Effect of Mode Bits on Compiler-Generated Code Stack Frame Layout Stack Frame Example N-Intrinsic Functions Vector N-Intrinsics ETSI to N-Intrinsic Mapping Parameter Output Syntax Argument Constraints SDK Utilities and GNU Counterparts sdar p Keyletter Options sdar p Keyletter Modifiers sdstrip Options sdnm Options sdsize Options sdstrings Options sdobjdump Options sdobjcopy Options ZISIM Command-line Options ZISIM Command Summary ZISIM400 specific commands ZISIMG2 specific commands Configurable ZISIM Attributes Default Arguments for show dmem Default Arguments for show imem I/O Device Memory Map and Associated Files ZSIM Command-line Options Command-line Options for zsim400 Command-line Options for zsimg2 ZSIM Command Summary ZSIM400 specific commands 1-3 1-4 3-2 3-4 3-4 3-5 3-8 3-10 3-11 3-17 3-18 3-19 3-23 3-24 6-1 6-3 6-4 6-6 6-8 6-9 6-11 6-13 6-15 7-3 7-4 7-6 7-7 7-16 7-20 7-20 7-24 8-3 8-4 8-5 8-5 8-9
xxi
8.6 8.7 8.8 8.9 8.10 9.1 9.2 9.3 9.4 9.5 9.6 9.7 10.1 10.2 10.3 10.4 11.1 11.2 11.3 B.1 C.1 D.1
ZSIMG2 specific commands Configurable ZSIM Attributes Default Arguments for show dmem Default Arguments for show imem I/O Device Memory Map and Associated Files Debugger Names SDBUG-Only Options SDBUG Target ZISIM Simulator Commands SDBUG Target ZSIM Commands SDBUG UART Connection Commands SDBUG JTAG Commands Hardware-Assisted Debugging Commands Compiler/Assembler Options Linker options ZSP IDE Toolbar Command Line Debugger Executables Debugger Targets Keyboard Shortcuts ZSP400 Control Registers G2 Control Registers Long Intrinsic Functions
8-10 8-22 8-28 8-29 8-33 9-2 9-2 9-4 9-5 9-8 9-9 9-10 10-13 10-16 10-30 10-35 11-2 11-2 11-16 B-1 C-1 D-1
xxii
Chapter 1 Introduction
The ZSP Software Development Kit (ZSP SDK) from LSI Logic supports all aspects of software development for systems incorporating devices based on the ZSP400 and ZSPG2 architectures. The ZSP SDK includes an optimizing C cross compiler, assembler, and linker, both a functionalaccurate simulator and a cycle-accurate simulator, and a source- and assembly-level debugger. The ZSP SDK is available for Windows 95, Windows 98, Windows NT, and Solaris platforms. For the Windows platforms only, the software development tools can be used in the context of the SDK Integrated Development Environment (IDE), which includes a project manager and a GUI debugger. The GUI debugger provides a graphical environment for developing and debugging your code, with interactive viewing and control of project source files and run-time data.
ZSP SDK Software Development Kit
1-1
1.1 Overview of the SDK Tools
The ZSP SDK tools are all placed under one directory which is referred to with the environment variable SDSP_HOME. The sdspI subdirectory contains all tools related to the ZSP400 architecture. The ZSPg2 subdirectory contains all tools related to the ZSPG2 architecture. There are no dependencies between the two directories. Users who only need tools for the ZSP400 can delete the ZSPg2 subdirectory. Likewise, users who only need tools for the ZSPG2 can delete the sdspI subdirectory. The two subdirectories closely mirror one another. Both have the following subdirectories: bin, lib, include, misc, tmp. The bin directories contain the command-line tools. The lib directories contain the C libraries. The include directories contain the C header files. The misc directories contain auxilary files. The tmp directories are used by the tools for temporary space. The GNU based tools for the ZSP400 all have a "sd" prefix. The analgous tools for ZSPG2 all have a "zd" prefix. In addition the assembly optimizer, sdopt/zdopt, also follows this prefix convention. The simulators do not follow this convention. The ZSP400 simulators are: zsim400 and zisim400. The ZSPG2 simulators are: zsimg2 and zisimg2. The ZSP SDK also supports users who want to take assembly and C code written for the ZSP400 architecture and run it without modification on the ZSPG2 architecture. The compiler zdxcc compiles for a ZSPG2 target but uses the calling convention and pointer sizes designed for the ZSP400. The ZSPg2 directory also contains a subdirectory libg1g2, which contains C libraries for zdxcc. There is also a debugger, zdxbug, for debugging code developed with zdxcc. The ZSP SDK tools are based on the GNU tools from the Free Software Foundation, Inc. The GNU project has well-proven software development tools that have been successfully ported to many different target machines and platforms. Documentation for the GNU project tools can be obtained from the web site www.gnu.org and the FTP site prep.ai.mit.edu. To gain access to the FTP site, log in as `anonymous' and type your e-mail address as the password. The descriptions of the tools in this document, for the most part, include only the differences from their GNU counterparts (refer to Table 1.1).
1-2
Introduction
Table 1.1
SDK Tools and GNU Counterparts
GNU Equivalent gcc
Tool sdcc zdcc zdxcc sdas zdas sdld zdld sdbug400 zdbug zdxbug
Function Compiles
as ld gdb
Assembles Links Debugs
The GNU tools have been enhanced so as to take advantage of the many high-performance features of the ZSP LSI402ZX and LSI403Z devices and ZSP400-based ASICs, such as single-cycle multiplyaccumulate instructions, fast context switching, circular buffer support, single-cycle compare/select, and zero-overhead loops. The SDK provides utilities for manipulating the files that are generated by the tools during project creation. These SDK-specific utilities, described in Table 1.2, replace their GNU counterparts.
Overview of the SDK Tools
1-3
Table 1.2
SDK Utilities and GNU Counterparts
GNU Equivalent ar nm objdump ranlib strings size strip objcopy
Utility sdar zdar sdnm zdnm sdobjdump zdobjdump sdranlib zdranlib sdstrings zdstrings sdsize zdsize sdstrip zdstrip sdobjcopy zdobjcopy
Function Creates, modifies, and extracts files from an archive. Lists symbols from object files. Displays information from object files. Generates an index for an archive. Prints the printable characters in the files. Lists section sizes and total size of object file. Discards symbols from object files. Copies and translates object files.
The SDK Tools also includes the following non-GNU-based tools:
* *
The compiler's optimizer, sdopt/zdopt/zdxopt, performs additional optimizations to those performed by SDCC/ZDCC/ZDXCC. Both the functional-accurate and cycle-accurate simulators are provided in a standalone form that support a simple command-line interface and that can be provided in a dynamic linkable format that can be used in conjuction with the debugger. For Windows platforms only, the GUI tools include an IDE and a GUI Debugger.
*
For Solaris platforms, there are freely-available GUI front ends that do not have all the capabilities of the GUI supplied by LSI Logic for Windows platforms, but that can be configured for use with all the LSI Logic ZSP SDK Tools.
1-4
Introduction
1.2 Overview of Software Development Using the SDK Tools
An overview of the software development process utilizing the SDK tools is shown in Figure 1.1. As shown in the figure, the compiler accepts C source files (.c ) and produces a relocatable assembly language source module (.s). The assembly source file is input to the assembler, which translates the module into a relocatable object file in the Executable and Linkable Format (ELF) file format (.obj (Windows) or .o (UNIX)). ELF files are then linked with other ELF files (for example, library files) to produce a single executable ELF load file (a.out). The load file can be loaded into host memory for symbolic simulation/debugging, or it can be downloaded to a ZSP architecture-based target system for real-time debugging. On Windows 95/98/NT and Solaris platforms, the tools can be accessed using the standard GNU command-line interface, as described in Chapter 3, "C Cross Compiler" through Chapter 9, "Debugger." On Windows 95/98/NT platforms, the tools can also be accessed using the the ZSP Integrated Development Environment (ZSP IDE), (Chapter 10, "ZSP Integrated Development Environment (ZSP IDE)"), and the ZSP IDE Debugger (Chapter 11, "ZSP IDE Debugger").
Overview of Software Development Using the SDK Tools
1-5
Figure 1.1
Overview of Software Development
C Source Files
C Compiler
Assembler Source Files
Optimizer
Assembler Source Files
Macropreprocessor
Assembler
Listing File
Archiver
ELF Object File
Libraries
Linker
ELF Load File
Debugger
Simulator
1-6
Introduction
Chapter 2 Installation
This chapter describes how to install the ZSP Software Development Kit. The SDK is available for Windows 95, Windows 98, Windows NT, and Solaris. The media used to provide the tools is a CD-ROM.
2.1 Contents of the CD-ROM
The CD-ROM has the following five top-level directories:
*
doc Contains the complete documentation for the SDK tools and the GNU tools.
* *
examples Contains example code for the SDK tools. solaris Contains initialization code and tools for installing the SDK on the Solaris platform.
*
windows Contains the initialization code and tools for installing the SDK on Windows 95/98/NT platforms, and examples that can be added to an ZSPIDE project.
2.2 Installation on Windows Systems
The minimum system requirements for the SDK tools are
*
a Pentium Pro-based PC
ZSP SDK Software Development Kit
2-1
* *
64 Mbytes of RAM 48 Mbytes of Disk Space
On Windows NT systems, you must have administrator privileges to install the ZSP SDK Tools.
2.2.1 Installing SDK Tools
Before you install the SDK tools, make sure you have uninstalled any older version. Refer to Section 2.3, "Uninstalling the SDK Tools on Windows Systems." Step 1. Insert the CD-ROM in the CD drive, click Add/Remove Program on the Control Panel, then click Install and select D:\windows\Setup.exe. Step 2. Follow the Setup Instructions. Step 3. A dialog box will be displayed for entering the serial Number.
Step 4. Type the serial Number, and then click on the Next button. The dialog box shown below will be displayed.
2-2
Installation
Step 5. The default directory is C:\Program Files\SDK Tools\. You can change the default directory by clicking on the Browse button, specifying a directory name, and then clicking OK. The Setup program installs the SDK files in the selected directory. When the setup is complete, a dialog box is displayed confirming successful setup. By default, the Setup program installs the files listed below in C:\Installation_Directory\sdspI\bin, where Installation_Directory is the directory specified in Step 5
.
Filename elfread.exe libzisim400.dll1 libzsim400.dll1 libzperiph.dll1
Function Produces a simple dump of entire contents of an object file Dynamic link library used in sdbug400 for target zisim Dynamic link library used in sdbug400 for target zsim Dynamic link library used in sdbug400 for target zsim
(Sheet 1 of 2)
Installation on Windows Systems
2-3
Filename sdar.exe sdas.exe sdbug400.exe sdcc.exe sdcc1.exe1 sdcpp.exe1 sdld.exe sdnm.exe sdobjcopy.exe sdobjdump.exe sdopt.exe1 sdranlib.exe sdsize.exe sdstrings.exe sdstrip.exe zisim400.exe zsim400.exe
Function Archive utility Assembler Source-level debugger for ZSP400-based Devices Driver Compiler Preprocessor Linker Symbol listing utility Object file copying utility Object dump utility Optimizer Ranlib utility Size utility String print utility Symbol discarding utility Functional-accurate simulator for ZSP400-based devices Cycle-accurate simulator for ZSP400-based devices
(Sheet 2 of 2) 1. These files are not intended to be used on the command line, but instead are always called by other functions.
2-4
Installation
The libraries listed below are installed by default in the directory C:Installation_Directory\sdspI\lib.
Filename crt0.obj libc.a libg.a liblongc.a Function Startup file C library C library with debug information C library with long calls.
The header files listed below are installed by default in the directory C:\Installation_Directory\sdspI\include.
Filename cbuf.h ctype.h creg.h dsp.h libsdsp.h limits.h N_Intrinsic.h q15.h setjmp.h simios.h stdarg.h stddef.h stdio.h stdlib.h string.h Function Circular buffer Standard header file Control registers L-Intrinsics SDSP-specific printing Standard header file N-Intrinsics Support file Standard header file Standard header file Standard header file Standard header file Standard header file Standard header file Standard header file
Installation on Windows Systems
2-5
By default, the Setup program installs the files listed below in C:\Installation_Directory\ZSPg2\bin, where Installation_Directory is the directory specified in Step 5
.
Filename elfread.exe libzisimg2.dll1 libzidlmssg2.dll1 zdar.exe zdas.exe zdbug.exe zdxbug.exe zdcc.exe zdxcc.exe zdcc1.exe1 zdxcc1.exe1 zdcpp.exe1 zdxcpp.exe1 zdld.exe zdnm.exe zdobjcopy.exe zdobjdump.exe zdopt.exe1 zdxopt.exe1 zdranlib.exe (Sheet 1 of 2)
Function Produces a simple dump of entire contents of an object file Dynamic link library used in zdbug and zdxbug for target zisim Dynamic link library used in zdbug and zdxbug for target zisim Archive utility Assembler Source-level debugger for ZSP500-based Devices Source-level debugger for ZSP500-based devices running code designed for ZSP400 Compiler Cross ("X") compiler for ZSP400 to ZSP500 Compiler Driver for zdcc Compiler Driver for zdxcc Preprocessor Preprocessor for zdxcc Linker Symbol listing utility Object file copying utility Object dump utility Optimizer Optimizer for ZSP400 to ZSP500 code. Ranlib utility
2-6
Installation
Filename zdsize.exe zdstrings.exe zdstrip.exe zisimg2.exe
Function Size utility String print utility Symbol discarding utility Functional-accurate simulator for ZSP400-based devices
(Sheet 2 of 2)
The libraries listed below are installed by default in the directory C:Installation_Directory\ZSPg2\lib.
Filename crt0.obj libc.a libg.a Function Startup file C library C library with debug information
The libraries listed below are installed by default in the directory C:Installation_Directory\ZSPg2\lib.g1g2
Filename crt0.obj libc.a libg.a libalg.a Function Startup file C library C library with debug information Basic signal processing functionality
Installation on Windows Systems
2-7
The header files listed below are installed by default in the directory C:\Installation_Directory\ZSPg2\include.
Filename cbuf.h ctype.h creg.h dsp.h libsdsp.h limits.h N_Intrinsic.h q15.h setjmp.h simios.h stdarg.h stddef.h stdio.h stdlib.h string.h Function Circular buffer Standard header file Control registers L-Intrinsics SDSP-specific printing Standard header file N-Intrinsics Support file Standard header file Standard header file Standard header file Standard header file Standard header file Standard header file Standard header file
The files listed below are installed by default in the directory C:Installation_Directory\ide\bin
Filename en.rc guidebug.exe ZSPide.exe Function IDE menu resource GUI debugger frontend. IDE for the ZSP family of processors.
2-8
Installation
2.2.2 Restarting Windows
The Setup program installs system files and updates some shared files that are required for running the SDK tools. The system prompts you to reboot after you have installed the SDK tools.
Click Finish to exit from the Setup program.The system will be restarted according to the option selected in the above dialog box.
2.3 Uninstalling the SDK Tools on Windows Systems
Perform the following steps to uninstall the SDK tools: Step 1. Open the Control Panel window. (The Control Panel is accessed by clicking on the Start menu, then selecting Settings, then selecting Control Panel. Step 2. In the Control Panel window, double-click on Add/Remove Program. Step 3. Then select the LSI LOGIC SDK tools and click on Add/Remove. In the dialog box shown below, click on Remove to uninstall the tools.
Uninstalling the SDK Tools on Windows Systems
2-9
2.4 Installation on Solaris Systems
The ZSP SDK may be hosted on the Solaris 2.6 operating system and later versions. Step 1. If your Solaris system has vold, it will automatically mount the CD-ROM after it has been inserted. To access the CD-ROM, change the directory to /cdrom/SDK. Step 2. If vold is not running, mount the CD-ROM and enter the following command: mount /dev/sr0 /mnt/cdrom Step 3. Use one of the following commands to invoke the installation script under /cdrom/SDK/solaris or /mnt/cdrom/solaris: /cdrom/SDK/solaris/sdsp_install or /mnt/cdrom/solaris/sdsp_install Step 4. Follow the directions given in the script.
2-10
Installation
Step 5. Specify an installation directory for the SDK tools. Assign the installation path to the SDSP_HOME environment variable, followed by a forward slash (/). For example, if you install the tools in MyInstallDirectory, assign the directory to the SDSP_HOME variable: SDSP_HOME = MyInstallDirectory/ Step 6. Export the SDSP_HOME variable. Step 7. If you want to be able to invoke the SDK tools from any directory, add the installation directory to the path. Step 8. In order to use the sdbug400 debugger, the environment variable LD_LIBRARY_PATH must be included in the installation path. Use the following command: setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:$SDSP_HOME/sdspI/bin The Setup program installs the SDK files. The following files containing the tools are installed in the directory $SDSP_HOME/sdspI/bin.
Filename elfread sdar sdas sdbug400 sdcc sdcc1 sdcpp sdld sdnm sdobjcopy Function Produces a simple dump of entire contents of an object file Archive utility Assembler Source-level Debugger for ZSP400 Driver Compiler Preprocessor Linker Symbol listing utility Object file copying utility
Installation on Solaris Systems
2-11
Filename sdobjdump sdopt sdranlib sdsize sdstrings sdstrip zisim400 zsim400
Function Object dump utility Optimizer Random library (ranlib) utility Size utility String print utility Symbol discarding utility Functional-accurate simulator for ZSP400-based Devices Cycle-accurate simulator for ZSP400-based Devices
The libraries listed below are installed in the directory $SDSP_HOME/sdspI/lib.
Filename crt0.o libc.a libg.a
Function Startup file C library C library with debug information
The header files listed below are installed in the directory $SDSP_HOME/sdspI/include.
Filename cbuf.h ctype.h dsp.h libsdsp.h limits.h
Function Circular buffer Standard header file L-Intrinsics SDSP-specific printing Standard header file
2-12
Installation
Filename N_Intrinsic.h q15.h setjmp.h simios.h stdarg.h stddef.h stdio.h stdlib.h string.h
Function N-Intrinsics Support file Standard header file Standard header file Standard header file Standard header file Standard header file Standard header file Standard header file
For both the Windows and Solaris setups, there are additional files and directories installed by the Setup program that are required for running the tools. For this reason, do not delete or modify any of the files or directories in the installation directory. The ZSP SDK tools use the tmp directory, which is created during setup, to store temporary files. The misc directory contains a file called mapfile. This file contains information about the scan chain of the target processor that is used for hardware-assisted debug with the JTAG port (on Windows platforms only). The correct map file is required for hardware-assisted debugging. The map file supplied with the ZSP SDK tools corresponds to the LSI402ZX rev2. If you are using a different ZSP400-based part, you must replace the map file installed during setup with the proper map file for your device.
Installation on Solaris Systems
2-13
2-14
Installation
Chapter 3 C Cross Compiler
This chapter describes the SDK C Cross Compiler and the compilation process. The SDK C Cross Compilers; SDCC, ZDCC, and ZDXCC; are based on the GNU C compiler (GCC) from the Free Software Foundation. SDCC is the compiler for the ZSP400 architecture. ZDCC is the compiler for the ZSPG2 architecture. ZDXCC is targeted for the ZSPG2 architecture, but it uses the same calling convention and pointer size as SDCC. This allows C/assembly programs written for the ZSP400 architecture to be easily ported to the ZSPG2 architecture. CC will be used to refer to all three compilers. GCC is described in Using and Porting GNU CC, by Richard M. Stallman, Free Software Foundation, June 1996. The description of CC in this chapter, for the most part, includes only the differences from GCC. The compiler is invoked from the shell using the following command: cc [options] sourcefile The command-line options and source file name extension determine the type of compilation. In the simplest case, with no options and a .c source file, the compiler will produce an executable, a.out.
ZSP SDK Software Development Kit
3-1
3.1 Compiler Options
The CC compiler supports all GCC compiler options in addition to the SDK-specific options described in Table 3.1. Table 3.1
Option -mlong_call
Compiler Options
Description The compiler generates code for a call instruction using a register operand. Use this option to resolve the limitation of the call immediate range. The compiler disables the assembly optimizer, sdopt/zdopt/zdxopt. By default, the optimizer is automatically invoked at optimization levels -O1, -O2 and -O3. The compiler generates code for a conditional branch by using a register operand. The compiler generates code for an unconditional branch by using a register operand. Enable the compiler to generate mac and macn instructions without using intrinsics. Use this option only if the code generated will be run with the sat, q15, sre and mre bits of %fmode turned off. Use large data model. Availability SDCC ZDCC ZDXCC1 SDCC ZDCC ZDXCC SDCC ZDXCC SDCC ZDXCC SDCC ZDXCC
-mno_sdopt
-mlong_cond_branch2 -mlong_uncond_branch3 -minfer_mac
-mlarge_data
ZDCC
1. Since the range of a call immediate on ZSPG2 is 16-bits versus 13-bits on ZSP400, the -mlong_call option will be less frequently needed for ZDXCC and ZDCC. 2. This option is preserved for backward compatibility with previous versions of the SDK, but it is no longer needed, since the compiler will automatically use register based branches when needed. This option will be removed in a future version of the SDK. 3. (same as 2.)
The -mlong_call option is frequently necessary with SDCC because call-immediates on the ZSP400 architecture have a 13-bit range, and its use is therefore recommended for applications that are larger than the range of a call-immediate. The ZSPG2 architecture has a larger call immediate range (16-bits), so this option is not as critical for it. Better performance and code size can be obtained by selectively using the mlong_call option, but this may require repetitive trial and error to determine which files can safely be converted to use call-immediates. One important exception is a file which does not call a function external
3-2
C Cross Compiler
to the file; in this case, the necessity of -mlong_call does not depend on other files or on the link order--this kind of file will either always require -mlong_call or it will never require it. Note that with SDCC, the use of -mlong_call does not guarantee that all calls will be long calls; that is, the assembly optimizer, sdopt, will convert long calls to call immediates if it can determine that such a conversion is safe. The assembly optimizer can be disabled by specifying the -mno_sdopt option; otherwise, it is automatically invoked when optimization is selected. Note that to debug optimized code, the -mno_sdopt option should be used, because the assembly optimizers perform optimizations that make debugging extremely difficult. sdopt takes in assembly generated by the compiler proper and optimizes it to produce improved assembly. The optimizations that sdopt performs include simplification of constant generation, conversion of loops to use loop registers, dead code elimination, loop invariant code motion, conversion of long calls to call-immediate, instruction scheduling, and improved register utilization. zdopt takes in assembly generated by ZDCC and optimizes it to produce improved assembly. The optimizations that zdopt performs include dead code elimination, loop invariant code motion, instruction scheduling, and improved register utilization. ZDCC supports two models of memory. The default small memory model requires that data and bss sections be placed in the first 64K words of data memory. The large data model has no requirements on the size or placement of the data and bss sections. The large data model is selected with the "-mlarge_data" option. For both models, the pointer size is 32bits. Both models allow stack and heap space to use all addressable memory. Code generated with the small data model will be more compact and have better performance than code generated with the large data model. The small data model allows a shorter instruction sequence to be used to access memory in the data or bss sections.
Compiler Options
3-3
Some of the key options that control the compiler's output are shown in Table 3.2. Table 3.2
-c -o file -E -S -save-temps
Output Options
Compile or assemble source files but do not link. Output file is named by replacing the suffix of the source file with `.o'. Place output in file. This option is applicable whether the output is preprocessed C, assembly, an object file, or an executable. Stop after preprocessing. Output is sent to standard output. Stop after compilation. Do not assemble. Output file is named by replacing the `.c' suffix with `.s'. Store the intermediate preprocessed C, assembly, and object files permanently. The names used for these intermediate files will be based on the name of the input file: compiling foo.c with -save-temps will produce foo.i, foo.s, and foo.o. Generate debugging information for use by the debugger.
-g
The optimization levels supported by GCC are described in Table 3.3. Table 3.3
Option -O0 -O1 -O2
Optimization Options
Description No optimization is performed. All variables are placed on the stack. Only those optimizations that allow the debugger to behave as expected are performed. Only those optimizations that do not greatly increase code size are performed. These optimizations include dead-code elimination, constant propagation, common subexpression elimination, and loop invariant code motion. All optimizations performed at level -O2 are performed, as well as function inlining and loop unrolling.
-O3
3.2 Compiler Conventions
This section describes the software conventions defined by the SDK assembler and compiler. You must follow these conventions when writing assembly-language routines that will be called by your C program.
3-4
C Cross Compiler
3.2.1 Data Type Conventions
The compiler's representation of C data types is summarized in Table 3.4. The q15 data type can be printed by the fprintf and printf functions. The %q format specifier will print a 16-bit value in fixed-point notation. For example, the call: printf("%q\n",0x6000); will print: 0.75000 Table 3.4
C Data Type char unsigned char int short int unsigned short int q15 enum pointer long unsigned long accum_a accum_b
Compiler's Representation of C Data Types
Representation 16 bits 16 bits 16 bits 16 bits 16 bits 16 bits 16 bits 16 bits with SDCC/ZDXCC 32 bits with ZDCC 32 bits 32 bits 32 bits 32 bits
Use the accum_a and accum_b data types to select a specific register for variable storage: variables declared as type accum_a or accum_b are placed in registers r1r0 and r3r2 respectively with SDCC/ZDXCC. They are placed in r13r12 and r15r14 respectively with ZDCC. This change was necessary with ZDCC because registers r0-r3 are clobbered by the ZSPG2 calling convention. The accum_a and accum_b data types can be
Compiler Conventions
3-5
used to declare local variables; global accumulators are not supported. From the compiler's point of view, accum_a and accum_b are 32-bit variables that must be stored in a specified register. On the ZSP400, the accum_a and accum_b data types are placed in r1r0 and r3r2, respectively, to allow the use of accumulator-specific operations. Although the compiler treats accum_a and accum_b as 32-bit variables, the accumulator instructions (for example, mac.a, mac2.a, macn.a ... ) operate on a 40-bit accumulator. The high-order 8 bits for each accumulator are in the %guard register. If 40-bit accumulators are needed, the high-order bits can be accessed through inline assembly instructions that read or modify the %guard register. In ZSPG2, since every GPR pair supports accumulator operations, other accumulators can be used by declaring them with: register long acc_c asm("rX"); In fact, accum_a and accum_b declarations are equivalent to: register long x asm ("rX"); where "X" is the appropriate register. It should be remembered that only accumulators r12-r15 have their guard bits preserved across calls.
3.2.2 Register Usage
3.2.2.1 SDCC/ZDXCC Register Usage Register usage SDCC/ZDXCC is summarized below. Registers r0 through r15 are general-purpose registers, and registers beginning with `%' are control registers.
*
Registers used by the compiler: r0-r15, %fmode, %smode, %amode, %hwflag, %loop0, %loop1, %loop2, %loop3, %rpc, %pc, %cb0_beg, %cb0_end, %cb1_beg, %cb1_end, %guard. Stack pointer: r12 Parameter registers: r4-r6 Callee preserved registers: r0-r3, r7-r12, r14, r15, %guard There are no caller saved registers.
* * * *
3-6
C Cross Compiler
*
Return registers: r4 for 16-bit return values, and r5r4 for 32-bit return values.
The mode registers are never modified by SDCC/ZDXCC except through inline assembly. The circular buffer registers are never accessed or modified except through predefined macros in the header file cbuf.h. The file cbuf.h also has predefined macros to set and clear the cb0 and cb1 bits in %smode. 3.2.2.2 ZDCC Register Usage Register usage by ZDCC is summarized below. Registers r0-r15 are general-purpose registers, a0-a7 are address registers, n0-n7 are index registers, g0-g7 are guard registers and registers beginning with `%' are control registers.
*
Registers used by the compiler: r0-r15, a0-a7, n0-n7, g0-g7, %fmode, %smode, %amode, %hwflag, %loop0-%loop3, %rpc, %pc, %cb0_beg-%cb3_beg, %cb0_end-%cb3_end. Stack pointer: a7 Parameter registers: r2-r7, a0, a1, a6 Callee preserved registers: r8-r15, g6, g7, a2-a5, a7, n4-n7, %loop2, %loop3 Scratch registers: r0, r1, g0-g5, n0-n3, %loop0, %loop1 Return registers: a0 for pointer values, r4 for 16-bit return values, and r5r4 for 32-bit non-pointer values.
* * * * *
The mode registers are never modified by ZDCC except through inline assembly. The circular buffer registers are never accessed or modified except through predefined macros in the header file cbuf.h. The file cbuf.h also has predefined macros to set and clear the cb0-cb3 bits in
Compiler Conventions
3-7
%amode. Table 3.5 shows the mode bits that may affect the behavior of compiler-generated code. Table 3.5
Mode Register
Effect of Mode Bits on Compiler-Generated Code
Mode Register Bit Affects Nonintrinsic Code Required Entry Value (before C function call) SDCC ZDXCC ZDCC May be Modified Within Function
SDCC ZDXC C %amode ld st cbX %fmode sat1 q152 sre3 mre4 %smode shd5 lis sis cbX6 yes yes yes yes n/a yes no
ZDCC
SDCC ZDXCC
ZDCC
yes yes yes no n/a 0
0 0 0 x x x x n/a yes yes yes x 0 0 0 n/a x x 0 no no no yes n/a yes
no no yes yes yes yes yes n/a no no no
yes no
dir7 ddr8
yes yes
x x
no no
1. Wtih SDCC/ZDXCC, the sat bit of %fmode can affect nonintrinsic code because of the add and subtract instructions. Nonintrinsic code expects unsaturated arithmetic. If you require saturated arithmetic for some intrinsics, it is safest to enable saturation over as small a region of code as possible, because the sat bit also affects adds and subtracts that must not be saturated (e.g. address arithmetic, stack pointer manipulation, counters, etc. ). If you use the -minfer_mac option, the compiler also generates mac and macn instructions, which are also affected by the sat bit. 2. With SDCC/ZDXCC, the q15 mode bit affects nonintrinsic code if the -minfer_mac option is used. 3. The sre bit of %fmode affects nonintrinsic code because of the shra and shra.e instructions. Only perform right shifts of signed variables when the sre bit is cleared.
3-8
C Cross Compiler
4. With SDCC/ZDXCC, the mre mode bit affects nonintrinsic code if the -minfer_mac option is used. 5. This bit is ZSP400 specific and selects/unselects the use of shadow registers. Compiled code operates correctly with either shadow registers or nonshadow registers. 6. For ZSPG2, these bits affect the behavior of r14 and r15. They exist for compatibility with ZSP400. They should never be set in code compiled with the ZDCC. When using SDCC/ZDXCC, to prevent these bits from affecting nonintrinsic code, clear these bits when the portion of code requiring circular buffers is exited. 7. This bit controls whether instructions are fetched from internal or external memory. Compiled code operates correctly when it resides in internal or external memory, though normally it resides in internal memory. 8. This bit controls whether data is fetched from internal or external memory. Compiled code operates correctly when data resides in internal or external memory, though normally data resides in internal memory. Note that data includes the stack, and that compiled code does not operate correctly if global data resides in one memory and the stack resides in another memory.
3.2.3 Conventions Used for Passing Parameters
SDCC/ZDXCC's conventions for passing parameters are described below.
* * * * *
The first three (16-bit) word parameters (scalar type) are passed in registers r4-r6. All other parameters are passed on the stack. A 16-bit value is returned in r4; a 32-bit value is returned in r5r4. A structure is returned using a hidden pointer, which is passed by the caller in r4. A structure is passed using two arguments. The first argument is a pointer to the structure, and the second argument is the structure to be passed. The pointer to the structure is a 16-bit value and can be passed in a register if it is one of the first three word-sized arguments. The second argument, the structure, is passed on the stack. For structures with a size of one or two words, the pointer argument is eliminated.
ZDCC's conventions for passing parameters are described below. Parameters are examined from first to last
* *
A pointer value will be passed in the first unused register in the following list: a0, a1, a6, r5r4, r7r6, r3r2. A 32-bit non-pointer value will be passed in the first unused register in the following list: r5r4, r7r6, r3r2, a0, a1, a6.
Compiler Conventions
3-9
* * * *
A 16-bit value will be passed in the first unused register in the following list: r4, r5, r6, r7, r2, r3. All other parameters are passed on the stack. A pointer value is returned in a0. A non-pointer 32-bit value is returned in r5r4. A 16-bit value is returned in r4. A structure is returned using a hidden pointer, which is passed by the caller in a0.
Note that registers that were skipped so that a 32-bit parameter could be passed can be used later when passing a 16-bit parameter. For example, a function with prototype: void f(int, long, int) will expect its' arguments to be in: r4, r6r7, and r5 respectively.
3.2.4 Run Time Stack
The C run time stack grows towards lower addresses in memory. The stack pointer (r12 with SDCC/ZDXCC, a7 with ZDCC) decrements when items are pushed on the stack. The initial memory location of the stack is specified in the initialization file crt0.o. Table 3.6 shows the layout of a function's stack frame. Table 3.6 Stack Frame Layout
Callee saved registers %rpc Local variables and temporaries Outgoing arguments (The stack allocates enough space to accommodate any call by the function.)
3-10
C Cross Compiler
Table 3.7 shows the two example stack frames for the functions foo and bar, after foo calls bar. Table 3.7
high address
Stack Frame Example
Callee saved registers of foo locals/temps of foo foo's stack frame
max args of all functions called by foo callee saved registers of bar locals/temps of bar low address max args of all functions called by bar bar's stack frame
Note that within the body of a function, the stack pointer points to the beginning of the next stack frame. When a function is called, the compiler places arguments into registers, if possible, and puts the remaining arguments in the outgoing arguments of the caller's stack frame. The compiler places any required arguments on the stack from lower to higher addresses. Thus the first argument placed on the stack is the one closest to the callee's stack frame. The function call is made after all the arguments have been properly placed.
3.2.5 Example Code for Function Prologue and Epilogue
3.2.5.1 SDCC/ZDXCC The following is a sample prologue that saves r0-r3, r7-r9, and %rpc and reserves 30 words of space on the stack. Note that with optimization, this code will be reordered with non-prologue code for better scheduling by sdopt.
Compiler Conventions
3-11
stdu stdu stu stdu mov stu mov sub
r0, r12, -2 r2, r12, -2 r7, r12, -1 r8, r12, -2 r13, %rpc r13, r12, -1 r13, 30 r12, r13
The appropriate epilogue code for the above prologue is shown below. ZSP interrupt routines expect the stack pointer to point to a writable location. This requirement prevents the use of the stack pointer to directly restore the saved registers. Instead, the stack pointer is copied to r6, and r6 is used to restore the saved registers. After all the registers are restored, r6 is copied back to the stack pointer.
mov mov add ldu mov lddu ldu lddu lddu add mov ret r6, r12 r13, 31 r6, r13 r13, r6, 1 %rpc, r13 r8, r6, 2 r7, r6, 1 r2, r6, 2 r0, r6, 2 r6, -1 r12, r6
3.2.5.2 ZDCC The following is a sample epilogue that saves r8, r9, a2, and %rpc and reserves 20 words of space on the stack. Note that with optimization, this code will be reordered with non-prologue code for better scheduling
pushd mov.e pushd pushd add r8, r8, r8, a2, a7, a7 %rpc a7 a7 -20
The appropriate epilogue code for the above prologue is shown below.
add popd popd a7, 20 a2, a7 r8, a7
3-12
C Cross Compiler
mov.e popd ret
%rpc, r8 r8, a7
3.2.6 Parameter Passing Examples
3.2.6.1 SDCC/ZDXCC In the example below, function foo calls function bar, passing two long (32-bit) arguments from r1r0 and r3r2. The first argument is placed in the stack at r12 + 1, and the second argument is placed at r12 + 3. Function bar has a frame size of 16 and accesses the passed arguments in function foo's outgoing argument stack space.
mov add stdu mov add stdu r13, 1 r13, r12 r0, r13, 2 r13, 3 r13, r12 r2, r13, 2 !! The first argument location on the stack !! Store r0 at r12+1 and r1 at r12+2. !! Compute r12+3 and store in r13. !! Store r2 in r12+3 and r3 in r12+4.
The function bar retrieves arguments from foo's stack space by loading the values from foo's outgoing argument space. The first word of foo's outgoing arguments is located at r12+(bar's stack space)+1, or r12+(16)+1.
mov ldx mov ldx mov ldx mov ldx r13, 17 r0, r12 r13, 18 r1, r12 r13, 19 r2, r12 r13, 20 r3, r12
3.2.6.2 ZDCC The following C code:
void callee(int i1, long l1, int i2, long l2, long l3, long *p1, long l4, long l5, long l6) { global = l5+l6;
Compiler Conventions
3-13
} void caller() { long a=7; callee(1,2,3,4,5,&a,7,8,9); }
The arguments will be passed in the following locations:
i1 l1 i2 l2 l3 p1 l4 l5 l6 r4 r7r6 r5 r3r2 a0 a1 a6 stack+1 stack+3
The above code will produce the following calling code sequence:
mov std mov mov std std mov mov mov mov mov mov mov mov mov add call a1, 8 a1, a7, 1 a0, 7 a1, 9 a0, a7, 5 a1, a7, 3 a6, a0 r4, 0x1 r6, 2 r7, 0 r5, 0x3 r2, 4 r3, 0 a0, 5 a1, a7 a1, 5 _callee !l5, fifth 32-bit non-pointer parameter passed on stack
!l6, !l4, !i1, !l1,
sixth 32-bit non-pointer parameter passed on stack fourth 32-bit non-pointer parameter passed in a6 first 16-bit parameter passed in r4 first 32-bit non-pointer parameter passed in r7r6
!i2, second 16-bit parameter passed in r5 !l2, second 32-bit non-pointer parameter passed in r3r2 !l3, third 32-bit non-pointer parameter passed in a0 !p1, first pointer parameter passed in a1
The function callee retrieves l5 and l6 from caller's stack space by loading the values from caller's outgoing argument space. The first word of caller's outgoing arguments is located at a7+(callee's stack space)+1, or a7+(0)+1.
mov add ldd ldd a0, a0, r4, r6, a7 1 a0 a7, 3
3-14
C Cross Compiler
3.3 Run Time Environment
The compiler run time environment is initialized in the startup file crt0.o on Solaris platforms or crt0.obj on Windows platforms. By default, the startup file is automatically linked by the compiler. The initialization file will fill the bss section with zeroes. The run-time memory map contains three main sections: text, data, and bss, in that order. The heap grows from lower addresses to higher addresses and starts after the bss section. The stack grows from higher to lower addresses, and starts at the address specified by the predefined variable __stack_start - 4, which has a default value of 0xF7FB for SDCC/ZDXCC and 0xFFEFFF for ZDCC. This can be modified as shown below. sdcc -Wl,-defsym,__stack_start=0xd000 test.c
3.4 C Run Time Library Functions
The libc.a libraries supplied with the C compiler contain the run time library functions. These functions are equivalent to those found in other C programming environments, having the same names and parameter lists. Thus existing programs that use these functions may be recompiled without any changes. The compiler provides a debugging form of the library, libg.a, which allows you to debug standard library functions.
Run Time Environment
3-15
The library functions are grouped into the following categories:
*
String functions (string.h) bcmp, bcopy, bzero, index, memchr, memcmp, memcpy, memmove, memset, rindex, strcat, strchr, strcmp, strcpy, strcspn, strlen, strncat, strncmp, strncpy, strpbrk, strrchr, strspn, strstr, strtok.
*
I/O functions (stdio.h) fopen, fclose, fwrite, fread, fgetc, fputc, fprintf, printf, sprintf, vfprintf, vprintf, vsprintf, getc, putc, getchar, putchar
The fprintf and printf functions have been extended to allow printing of the q15 data type. A "%q" format specifier will print a 16-bit value in fixed-point notation.
* * *
The filehandles stdin, stdout, and stderr are available for use with fwrite, fread, fgetc, fputc, and fprintf. Memory allocation functions (stdlib.h) malloc, free, mbtowc Interprocedural control flow functions (setjmp.h) setjmp, longjmp
In the case of I/O functions, the SDK performs file I/O by sending a message to the program running on the host (sdbug400, zsim400, zisim400, zdbug, zdxbug, zsimg2 or zisimg2). These messages will cause the host program to perform the requested file I/O operation. All host programs and all zdbug targets support file I/O.
3.5 N-Intrinsics
SDCC N-Intrinsics provide support for DSP instructions. N-Intrinsics are implemented as macros in the header file N_Intrinsic.h. The name of an N-Intrinsic begins with an N_ , followed by a suffix that indicates the operation's data type: _s for int, _l for long, and _h for high-order int of a long.
3-16
C Cross Compiler
To use N-intrinsics, add the following line in each of your C files: #include N-intrinsics are implemented by the compiler using the assembly instructions shown in Table 3.8. The older L-intrinsics are still supported and are described in Appendix D, "L-Intrinsic Functions." Table 3.8 N-Intrinsic Functions
Generated Code mac.acc x, y macn.acc x, y Analogous L-Intrinsic L_maca, L_macb L_macna, L_macnb L_mac2a, L_mac2b L_mula, L_mulb None norm_l norm_s extract_h L_deposit_h L_abs abs_s round L_shla shla
Intrinsic Function N_mac(accum acc, int x, int y) N_macn(accum acc, int x, int y)
N_mac2(accum acc, long x, long y) mac2.acc x,y N_mul(accum acc, int x, int y) N_muln(accum acc, int x, int y) N_norm_l(int ret, long a) N_norm_s(int ret, int a) N_extract_h(int ret, long a) N_deposit_h(long ret, int a) N_abs_l(long ret, long a) N_abs_s(int ret, int a) N_round_l(long ret, long a) N_shla_l(long ret, int a) N_shla_s(int ret, int a) mul.acc x, y muln.acc x, y norm.e ret, a norm ret, a ret = a[31:16] ret[31:16] = a ret[15:0] = 0 abs.e ret, a abs ret, a round.e ret, a shla.e ret, a shla ret, a
N-Intrinsics
3-17
3.5.1 Vector N-Intrinsics
The ZDCC compiler also provides N-Intrinsics for common vector operations. They are shown in Table 3.9. The vector N-Instrinsics will produce more efficient code than the equivalent non-vector code. Table 3.9
N-Intrinsic 1 N_vc_mac(accum acc, int *vec1, int inc1, int cnst, int len) N_vc_macn(accum acc, int *vec1, int inc1, int cnst, int len) N_vv_mac(accum acc, int *vec1, int inc1, int *vec2, int inc2, int len) N_vv_macn(accum acc, int *vec1, int inc1, int *vec2, int inc2, int len)
Vector N-Intrinsics
Functionality 2 for (i=0; i1. All increment values (inc1, inc2) must be -2, -1, 1, or 2. 2. The actual code generated will be more efficient than the functionally-equivalent code in this column.
Important:
If you use vector N-Intrinsics at optimization level 3 (-O3), you must also use the -fno-inline option. Functions with vector N-Intrinsics must not be inlined, since these intrinsics create labels. If these labels are inlined, they are duplicated and cause an error.
3.5.2 ETSI Functions
The SDCC's N-Intrinsics also allow access to processor-supported ETSI functionality, although the interface is different. For example, the ETSI code: y = norm_l(x); can be rewritten with N-Intrinsics as: N_norm_l(y,x);
3-18
C Cross Compiler
Another approach that preserves the ETSI defined interface would be to use N_norm_l to implement the ETSI function. For example, norm_l could be implemented as: static inline int norm_l(long src) { int ret; N_norm_l(ret,src); return(ret); } You may implement some ETSI functions can be implemented using NIntrinsics, but you must set mode bits in %fmode accordingly. For example, you can implement the ETSI function L_mac using N_mac, but you must also set the SAT and Q15 mode bits in %fmode. This correspondence between N-Intrinsics and ETSI functions is shown in Table 3.10. Table 3.10 ETSI to N-Intrinsic Mapping
fmode1 Register Bits ETSI Function abs_s extract_h L_abs L_deposit_h L_mac L_macN L_msu L_msuN L_mult L_shl mac_r N-Intrinsic N_abs_s N_extract_h N_abs_l N_deposit_h N_mac N_mac N_macn N_macn N_mul N_shla_l N_mac sat x x x x 1 0 1 0 x 1 1 q15 x x x x 1 1 1 1 1 x 1 sre x x x x x x x x x x x mre x x x x 0 0 0 0 0 x 1
N-Intrinsics
3-19
Table 3.10
ETSI to N-Intrinsic Mapping (Cont.)
fmode1 Register Bits
ETSI Function msu_r mult mult_r norm_l norm_s round
N-Intrinsic N_macn N_mul N_mul N_norm_l N_norm_s N_round_l
sat 1 x 1 x x x
q15 1 1 1 x x x
sre x x x x x x
mre 1 0 1 x x x
1. 1 = Set, 0 = Cleared, x = Don't Care
3.6 Circular Buffers
The cbuf.h header file provides the interface to the circular buffers. The header file's macros generate the necessary assembly instructions. To use a circular buffer, a pointer must be declared, the circular buffer boundaries must be set, and the circular buffer must be enabled. With SDCC/ZDXCC the pointer must be in r14 or r15. register int *pt asm("r14"); set_r14_cbuf(low,high); enable_r14_cbuf; With ZDCC, the pointer must be in a0 - a3. register int *pt asm("a2"); set_cbuf(CBUF_ID,low,high); enable_cbuf(CBUF_ID); CBUF_ID must be A0_CBUF, A1_CBUF, A2_CBUF or A3_CBUF. A circular buffer must have at least 4 ints or 2 longs. Circular buffers can be disabled using the following macros with SDCC/ZDXCC: disable_rn_cbuf;
3-20
C Cross Compiler
For ZDCC the macro is: disable_cbuf(CBUF_ID); There are special macros defined within cbuf.h to access the elements in a circular buffer. These macros are the same for all compilers. load_int_cbuf(dst,pt,inc) store_int_cbuf(src,pt,inc) load_long_cbuf(dst,pt,inc) store_long_cbuf(src,pt,inc) The inc parameter determines the number of elements to increment the pointer pt. The inc parameter must be a constant rather than a variable. For load_int_cbuf and store_int_cbuf, inc must be in the range 1-50. For load_long_cbuf and store_long_cbuf, inc must be in the range 1-25. It is legal to access a value pointed to by pt using *pt, so an increment value of 0 is not needed. The dst and src parameters are variables used for the destination and source values, respectively. Note that these parameters are not pointers to a location where the destination/source will be stored/accessed, but to the variables that will actually be stored/accessed. Note: You must disable circular-buffer arithmetic immediately after the final use of pt, because the compiler may reuse the register containing pt for other purposes. The code generated in this case would not expect the register to have circular arithmetic.
Because the registers supporting circular-buffer functionality are not saved and restored by function calls/returns, circular buffers should not be used with code containing function calls.
3.7 Accessing Control Registers
Macros have been defined in the header file to simplify accessing control registers.
Accessing Control Registers
3-21
read_creg(creg,var) - Puts the value of a control register into var. write_creg(creg,val) - Puts a value, which can be a variable or an immediate, into a control register. The val argument can be made by or-ing together the following masks for the following registers: Macros have also been defined to manipulate specific bits of control registers. bitset_creg(creg,bitnum) bitclear_creg(creg,bitnum) bitinvert_creg(creg,bitnum) The bitnumber and value arguments can be filled with macros which have been defined to the approiate value. The bitnumber and mask to access a specific bit has been defined to "bit name"_[MASK|BIT]. For example, to set the Q15 bit of %fmode, use the following macro: bitset_creg(%fmode,Q15_BIT);
3.8 Q15 Support
CC supports the Q15 data type. To use Q15 arithmetic, the q15 mode bit in the %fmode register must be set, as follows: bitset_creg(%fmode,Q15_BIT); The q15 mode bit affects Q15 multiplies and the N-Instrinsics N_mul, N_mac, N_macn, N_mac2, and the vector intrinsics. Q15 arithmetic can be disabled as follows: bitclear_creg(%fmode,Q15_BIT); This release of the SDK does not support Q15 division. The code produced for the Q15 data type is equivalent to that produced for the int data type, except for the following three cases:
*
The product of two Q15s is calculated with a mul instruction rather than an imul instruction.
3-22
C Cross Compiler
*
The 16-bit result of a Q15 product is the high-order 16 bits of the result produced by a mul instruction. The 16-bit result of an int product is the low-order 16 bits of the result produced by an imul instruction. The product of two Q15 constants is not simplified by the compiler.
*
The fprintf and printf functions have been extended to allow printing of the q15 data type. A "%q" format specifier will print a 16-bit value in fixed point notation.
3.9 Inline Assembly
Inline assembly that references C variables can be generated by using the asm directive.
3.9.1 Syntax
The basic syntax of the asm directive is: asm( "parameterized assembly" : output variable, ... : input expression, ... : explicitly clobbered register, ... );
3.9.2 Parameterized Assembly
The parameterized assembly consists of a text string containing the desired assembly output with parameters that will be replaced with registers or constants according to the arguments in output variable and input expression. The syntax of a parameter is shown in Table 3.11. Table 3.11
Format %n %mn %on
Parameter Output Syntax
Output register name or constant accumulator name high register name
Inline Assembly
3-23
In the table above, n is the index of the desired argument in output variable or input expression. The three formats--%, %m, and %o-- control the way an argument is printed in the generated assembly. For example, a variable of long type that the compiler has placed in r1 and r0 will be printed as r0 when the % format is specified, as a when the %m format is specified, or as r1 when the %o format is specified.
3.9.3 Variables and Expressions
The syntax for an output variable and input expression is: "constraint" (expression|variable) A constraint is used to describe the requirements that an instruction places on an argument. For example, an instruction that requires an argument to be in a particular register would put a constraint on that argument to ensure that the argument is placed in an allowed register. In example 3 in Section 3.9.5, "Examples of asm Directive", the acc variable is constrained to be in an accumulator register. The supported constraints are shown in Table 3.12. Table 3.12
Constraint = r e h c n
Argument Constraints
Effect output variable general-purpose register address register index register accumulator register constant same as indexed argument Availability All compilers All compilers ZDCC ZDCC All compilers All compilers All compilers
Note that a constant argument can be used with an r constraint. The SDK copies the constant to a register and uses the register as the argument. You can combine constraints, which can be useful for instructions that allow different types of arguments. For example, the shla instruction can accept either a register or an immediate argument.
3-24
C Cross Compiler
The appropriate constraint for this argument would be rn. In example 4 in Section 3.9.5, "Examples of asm Directive", the input parameter is constrained to be either a register or an immediate. Sometimes it is necessary for two arguments to be in the same register. This requirement can be described by constraints. The first argument should be described with whatever constraint is appropriate, and the second argument's constraint must be the index of the first argument. For example, the first argument of the add instruction is an output/input argument. You must list this argument as an output variable and an input expression. The constraint of this argument when it appears as an input expression should be the index of the argument when it appears as an output variable. In example 3 in Section 3.9.5, "Examples of asm Directive", the output argument and the first argument illustrate this technique.
3.9.4 Explicitly Clobbered Registers
The syntax for an explicitly clobbered register is: "register name" This entry tells the compiler that the assembly code generated will clobber the specified register. Thus the generated assembly code may use the specified register for scratch purposes.
3.9.5 Examples of asm Directive
The examples in the subsections below illustrate the usage of the asm directive. 3.9.5.1 Example 1 asm("norm.e %0, %1": "=r" (ret) : "r" (a)); The example shown above has one output argument, ret, and one input expression, a. If the variable ret is in r0 and the variable a is in r4, this directive produces: norm.e r0, r4
Inline Assembly
3-25
3.9.5.2 Example 2 asm("abs r5, %1\n\tst r5, %0" : : "e" (addr), "r" (val) : "r5"); The example shown above stores the absolute value of val at addr. Two instructions are generated by this directive. There are two input expressions and no output arguments. Note that register r5 is clobbered by this directive. If addr is in a0 and val is in r15, this directive produces: abs r5, r15 st r5, a0
3-26
C Cross Compiler
3.9.5.3 Example 3 asm("mac.%m0 %2, %o2" : "=c" (acc) : "0" (acc), "r" (val)); The example above adds the 32-bit product of the high and low 16 bits of val to acc. Note that the high part of val is obtained with the %o2 operand and that the accumulator is printed with the %m0 operand. Also note that acc is both an input and an output argument, and that the constraint for acc when it appears as an output argument is c, an accumulator, and when it appears as an input argument is 0, which tells the compiler that these two arguments must be in the same location. If acc is in r0 and val is in r3r2, the following code is generated: mac.a r2, r3 3.9.5.4 Example 4 asm("mov %%smode, %0" : : "rn" (val)); The example shown above sets %smode to val. Note that %smode is not specified as a clobbered register, because %smode has no meaning to the compiler. If val is a symbolic constant with the value 3, the following code is generated: mov %smode, 3 You can find additional examples of using the asm directive in the header file N_Intrinsic.h. 3.9.5.5 Example 5 asm("bits %smode, 7"); The example shown above sets bit 7 in %smode. This example illustrates the general rule that if the assembly statement contains an argument (as in Example 4, which contains the argument %0), a reference to a register must contain an additional per cent (%) sign. Example 5 contains no argument, so a single % preceding smode is used.
Inline Assembly
3-27
3.9.6 Optimization of Inline Assembly
For purposes of optimization, the compiler assumes that inline assembly has no effect except to modify the output variables. Thus inline assembly can be removed by optimization if none of the output variables is subsequently used. Inline assembly that must not be deleted or significantly moved should contain the keyword volatile following the asm directive, as shown below. asm volatile("bits %smode, 7"); The volatile keyword is implicit for inline assembly with no output variables. Thus, the use of volatile in the above example is redundant.
3.10 Assembly Optimizer and Handwritten Assembly
The assembly optimizers can be used to automatically generate the prologue and epilogue for an assembly function and then to schedule the entire function. sdopt -asm assemblyfile The output will be placed in standard output. The assembly optimizers expect input of the following format:
!PROLOGUE() !EPILOGUE
This will be transformed by the assembly optimizer to:
.set REGSAVE_SIZE_ : __FUNC_START_: __FUNC_END_: ret
All registers that must be preserved according to the C calling convention will be preserved. Note that the name REGSAVE_SIZE_ can be used if the size of the stack space used by the prologue/epilogue is needed. Any input in the assembly file outside of the
3-28
C Cross Compiler
!PROLOGUE and !EPILOGUE markers will be copied without modification.
3.11 Debugging Options
You can debug code compiled using the GCC-supplied -g option, which generates debugging information. You can attempt debugging with optimization turned on, though optimization makes debugging difficult. When debugging optimized code, use the -mno_sdopt option, because sdopt, zdxopt and zdopt do not preserve the location of debugging information. Using the -g option with optimization modifies the code generated in two ways. First, the debugging version of the C library is linked, rather than the optimized version. Second, leaf functions save and restore %rpc (without the -g option, this save and restore is removed by optimization). The -g option saves and restores this register, because the debugger requires it to examine the call stack.
3.12 Code Statistics
CC creates four labels and symbols that are useful in analyzing the code generated by the compiler. Every function will have a label placed on its first instruction and after its last instruction with the following formats: __FUNC_START_ __FUNC_END_ The difference of these two labels will give the code size of a function. A function will also have a label placed on its return instruction: __FUNC_EXIT_ This label is used for function profiling. Every function will also have an absolute symbol that shows the number of words of stack space used per invocation of the function. __FUNC_FRAME_SIZE_
Debugging Options
3-29
3.13 Example Compilations
3.13.1 Example 1
cc test.c -Tdata=0x1 This command invokes the C compiler, assembler, and linker and produces an executable file with the default name a.out. The -Tdata=0x1 command places the data at address 0x1 to prevent a NULL pointer from being a valid pointer.
3.13.2 Example 2
cc -c test.c This command invokes the C compiler and assembler only, producing an object file with the default name test.obj (Windows) or test.o (UNIX).
3.13.3 Example 3
cc -S test.c This command invokes the C compiler only, producing an assembly file with the default name test.s.
3.13.4 Example 4
cc -O3 test.c This command invokes the C compiler with the highest level of optimization, that is, including all level -O2 optimizations, as well as function inlining and loop unrolling. The assembler and linker are also invoked, and the output is an executable file with the default name a.out.
3-30
C Cross Compiler
Chapter 4 Assembler
The SDK Assembler (SDAS/ZDAS) is based on the GNU assembler, AS, from the Free Software Foundation. It is described in Using AS: The GNU Assembler, by Dean Elsner, et. al., Free Software Foundation, January 1994. The description of SDAS/ZDAS in this chapter, for the most part, includes only the differences from AS. SDAS is the assembler for the ZSP400 architecture. ZDAS is the assembler for the ZSPG2 architecture. In this chapter, unless otherwise noted, SDAS refers to both the ZSP400 and ZSPG2 assemblers. The assembler is invoked from the shell using the following command: sdas [options] sourcefile SDAS processes an assembly source file with the .s file extension and produces a relocatable object file in ELF format with the default file extension .obj (Windows) or .o (UNIX).
4.1 Assembly Language Syntax
The basic format of a SDK assembly language statement is: [ label: ] [ statement ] [ !comment ]
Labels are identifiers that start at the beginning of a line, with no leading spaces or tabs, and end with a colon. Identifiers begin with a letter (case is significant) or an underscore, and can continue with more letters, digits, and underscores. Assembly language instructions can be on the same line as a label. Examples: Start: start: !"Start" is a label !"start" is another (different) label
ZSP SDK Software Development Kit
4-1
loop: End
bnz start add r0, r1 bnz Start:
!"start" is a label reference !"loop" is a label ! Illegal reference (extra colon) ! Illegal label (missing colon)
Symbols beginning with `L are locally resolved, and are therefore not ' visible to the linker or to other modules. Assembler statements can be assembler directives or assembly language instructions. Assembler directives start with a period (`.'). Comments start with an exclamation mark (!) and continue until the end of the line. The symbol `#' at the beginning of the line indicates that it is a comment. Note that files with the .S extension can be assembled using sdcc, which causes the C preprocessor to run before the assembler. This enables users to use C-style comments and #defines in their assembly code. However using a -g option will not cause any debug symbol generation, since the source file is an assembly program. To turn on debug information for an assembly program with a .S extension, you can use sdcc with the -Wa and -dbg options (the -dbg option is described in Section 4.1.1.4, "Debugging Option (-dbg)," page 4-3). All assembly programs must be contained within a section. Putting .section ".text", "ax" before any assembly code ensures that the code gets assembled into the .text section. Please refer to the GNU assembler manual for more information on the section syntax and flag definitions.
4.1.1 Assembler Options
Please refer to the GNU assembler manual for a full description of all options available to the assembler. A few of the more frequently-used options as well as the options specific for the SDK are described below. 4.1.1.1 Suppress warnings (-W) This options prevents warnings from the assembler from being displayed on the screen.
4-2
Assembler
4.1.1.2 Output file (-o) Using -o objfile assembles the output into the object file specified. By default, if you do not use the -o option, the resulting object file is named a.out. 4.1.1.3 Include path (-I) The -I dir option is used to add the specified directory to the search list used by .include directives. 4.1.1.4 Debugging Option (-dbg) The -dbg option adds debugging information to the executable file, which allows you to debug the source file rather than the disassembled text. The usage is: sdas -dbg test.s where test.s is the name of the assembly file.
4.1.2 Assembler Directives
The following subsections describe some frequently-used assembler directives, as well as those that are specific to the SDK assembly language. 4.1.2.1 .walign The .walign directive aligns the location counter on the next word boundary specified by an integer argument. If the location counter is already aligned, no action is taken. Intervening words are filled with nop instructions. For example, .walign 32 4.1.2.2 .wspace The .wspace directive allocates space in a segment as specified by an integer argument. The location counter is incremented, regardless of alignment. For example, .wspace 7 ! Increment the location counter by seven. ! Align to the next 32-word boundary.
Assembly Language Syntax
4-3
An optional fill value can also be given. If no fill value is given, the space will be filled with zeroes. .wspace 7, 0xd800! Create 7 words of 0xd800
4.1.2.3 .word The .word directive allows a user to specify zero or more comma separated values to be assembled into memory. 4.1.2.4 .global The .global directive is used to declare a global symbol. If this directive is not used, a symbol defined in a partial program is visible only within its scope. The .global directive makes the symbol visible to the linker. 4.1.2.5 .section The .section directive assembles the code following it into the section name specified. Example: .section, ".text", "ax" This defines a section named ".text" - the characters following it tell the assembler that the code following the directive is allocatable and is a part of the instruction memory. Please refer to the GNU assembler manual for more information. Although GNU assembler documentation says unnamed sections go to the default .text section, it is necessary to specify sections explicitly for the ZSP SDK tools.
4.1.3 Assembler Special Cases
For all instructions that require a register pair, the even register must be specified as the operand. For the ZSP400 assembler only, If an odd register is specified, the even register of the register pair is used as the actual operand in the instruction, and the assembler displays a warning message. With the ZSPG2 assembler, zdas, an odd register will not be converted to an even register and an error will be message will be shown.
4-4
Assembler
For the ZSP400 architecture, a target function must be placed at an even address. If the value is odd, an error message is displayed. A function can be forced to start on an even address by using the .walign 2 directive. For the ZSPG2 architecture, there are no alignment requirements for call targets.
Assembly Language Syntax
4-5
4-6
Assembler
Chapter 5 Linker
The SDK Linker (SDLD/ZDLD) is based on the GNU linker, LD, from the Free Software Foundation. LD is described in Using LD: The GNU Linker, by Steve Chamberlain, Free Software Foundation, January 1994. SDLD is the linker for the ZSP400 architecture. ZDLD is the linker for the ZSPG2 architecture. Unless otherwise noted, SDLD refers to both the ZSP400 and ZSPG2 linkers. The linker processes the object files generated by the assembler (designated with the .obj extension on Windows or .o extension on UNIX) and produces an executable file in ELF format with the default name a.out. The linker is invoked from the shell using the following command: sdld [options] sourcefile
5.1 Sections
By default, the linker generates .text, .data and .bss sections. The .text sections contains code, .data contains data, and .bss contains uninitialized data. If there are additional user-defined sections specified in the linker script file, the linker will generate them also. By default, .bss follows .data in Data memory unless relocated using a linker script command. The following section names have special meaning only on the ZSP400 linker:
* *
.exttext_0 through .exttext_15 .extdata_0 through .extdata_15
ZSP SDK Software Development Kit
5-1
Code or data in these sections is placed in the appropriate external instruction or data memory, with the particular external page selected by the number in the section name. On the ZSP400 architecture, the offset of a call immediate instruction must be even. If the assembler cannot resolve this offset, the linker will. If the offset is odd, the linker displays an error message. Because the assembler will automatically align call immediate instructions on an even address, this error occurs only if the call target was on an odd address. To resolve this error, align the call target on an even address, using the .walign 2 directive.
5.1.1 Symbols
By default, program execution begins at __start. The entry point can be altered by specifying an alternate address, using the -e option. For example, the following command will cause execution to begin at address 0xabcd: sdld -e 0xabcd The C stack region will always be set to the internal data memory. The linker uses four symbols for stack-range checking:
* * * *
__stack_start: beginning of C stack, default setting is 0xF7FF with SDLD and 0xFFEFFF with ZDLD. __stack_end: ending address of C stack __stack_size.linker_defined: stack size calculated by linker __stack_size.user_required: user required stack size set in command line option
You can inspect the values of these symbols in the map file. The value of the symbol __stack_start or __stack_end can be set in a linker script file or by using the command-line option defsym sym=Value. The user-required stack size can be set using the command-line option stack_size=Value. The linker will report an error when the stack size is inadequate.
5-2
Linker
5.1.2 Linker command file
A linker command file (also called a linker script file) is a file containing linker commands that explicitly define symbols and locate sections in memory. A linker command file can be specified when the linker is invoked. An example linker command file is shown below. SECTIONS { .text 0x2000: {*(.text)} .data 0x3000: {*(.data)} vectors 0x0000: {*(vectors)} } The example above declares the output sections .text, .data, and vectors. Each output section is formed by the corresponding input sections from all files (as indicated by the `*'). Refer to the GNU ld man page for more information.
5.1.3 Linker options
The following subsections describe some frequently-used linker options, as well as those that are specific to the SDK assembly language.
Option -T linkercommandfile -o outputfile -l archive Description Replaces the linker's default script file with the specified linkercommandfile. Names the output file. By default, the output file name is a.out. Adds archive file archive to the list of files to link. The linker will search for files libarchive.a for every archive specified using this option. Adds searchdir to the list of directories to search for archive libraries and linker scripts. Multiple paths can be specified by using the L option multiple times. Prints the link map to stdout. A link map contains information on the mapping of symbols.
-L searchdir
-M
Sections
5-3
Option --defsym symbol=expression
Description Creates a global symbol in the output file containing the absolute address specified by the expression. This option can be used multiple times to create multiple symbols. Valid formats for expression are hexadecimal constants or the names of existing symbols. Locate the .bss section at the address specified by addr. Locate the .text section at the address specified by addr. Locate the .data section at the address specified by addr.
-Tbss addr -Ttext addr -Tdata addr
5-4
Linker
Chapter 6 Utilities
This chapter describes the SDK utility programs. The SDK provides additional utilities for manipulating files that are generated by the tools during project creation. These SDK-specific utilities, described in Table 6.1, replace their GNU counterparts. Tools for the ZSP400 architecture start with an "sd" prefix. Tools for the ZSPG2 architecture start with a "zd" prefix. Unless otherwise specified, the description of a utility applies to both the ZSP400 and ZSPG2 versions of the tools. Table 6.1 SDK Utilities and GNU Counterparts
GNU Equivalent ar nm
Utility sdar zdar sdnm zdnm
Function Creates, modifies, and extracts files from an archive. Lists symbols from object files. Displays information from object files. Generates an index for an archive. Prints the printable characters in the files. Lists section sizes and total size of object file. Discards symbols from object files. Copies and translates object files.
sdobjdump objdump zdobjdump sdranlib zdranlib ranlib
sdstrings strings zdstrings sdsize zdsize sdstrip zdstrip size strip
sdobjcopy objcopy zdobjcopy
ZSP SDK Software Development Kit
6-1
6.1 sdar
Format sdar [-]p[mod [relpos]] archive [member...] Description sdar creates, modifies, and extracts from archives. An archive is a single file holding a collection of other files in a structure that allows you to retrieve the original individual files (called members of the archive). The original files' contents, mode (permissions), timestamp, owner, and group are preserved in the archive, and can be restored on extraction. When you specify the modifier s, sdar creates an index to the symbols defined in relocatable object modules in the archive. Once created, this index is updated in the archive whenever sdar makes a change to its contents (save for the `q' update operation). An archive with such an index speeds up linking to the library, and allows routines in the library to call each other without regard to their placement in the archive. You may use `sdnm -s' or `sdnm --print-armap' to list this index table. If an archive lacks the table, another form of ar called sdranlib can be used to add just the table. Options
6-2
Utilities
The p keyletter specifies what operation to execute. It may be any of the following, but you must specify only one of them: Table 6.2
Option d
sdar p Keyletter Options
Description Deletes modules from the archive. Specify the names of modules to be deleted as member...; the archive is untouched if you specify no files to delete. If you specify the `v' modifier, ar lists each module as it is deleted. Prints the specified members of the archive, to the standard output file. If the `v' modifier is specified, show the member name before copying its contents to standard output. If you specify no member arguments, all the files in the archive are printed. Inserts the files member... into archive (with replacement). This operation differs from `q' in that any previously existing members are deleted if their names match those being added. If one of the files named in member... does not exist, ar displays an error message, and leaves undisturbed any existing members of the archive matching that name. By default, new members are added at the end of the file; but you may use one of the modifiers `a', `b', or `i' to request placement relative to some existing member. The modifier `v' used with this operation elicits a line of output for each file inserted, along with one of the letters `a' or `r' to indicate whether the file was appended (no old member deleted) or replaced. Displays a table listing the contents of archive, or those of the files listed in member... that are present in the archive. Normally only the member name is shown; if you also want to see the modes (permissions), timestamp, owner, group, and size, you can request that by also specifying the `v' modifier. If you do not specify a member, all files in the archive are listed. If there is more than one file with the same name (say, `fie') in an archive (say `b.a'), `ar t b.a fie' lists only the first instance; to see them all, you must ask for a complete listing--in our example, `ar t b.a'. Extracts members (named member) from the archive. You can use the `v' modifier with this operation, to request that ar list each name as it extracts it. If you do not specify a member, all files in the archive are extracted.
p
r
t
x
A number of modifiers (mod) may immediately follow the p keyletter, to specify variations on an operation's behavior:
sdar
6-3
Table 6.3
Option f
sdar p Keyletter Modifiers
Description Truncates names in the archive. GNU ar will normally permit file names of any length. This will cause it to create archives which are not compatible with the native ar program on some systems. If this is a concern, the `f' modifier may be used to truncate file names when putting them in the archive. Preserves the original dates of members when extracting them. If you do not specify this modifier, files extracted from the archive are stamped with the time of extraction. Normally, `ar r'... inserts all files listed into the archive. If you would like to insert only those of the files you list that are newer than existing members of the same names, use this modifier. The `u' modifier is allowed only for the operation `r' (replace). In particular, the combination `qu' is not allowed, since checking the timestamps would lose any speed advantage from the operation `q'. Quick append at end of files
o u
q
6-4
Utilities
6.2 sdstrip
Format sdstrip [-R sectionname | --remove-section=sectionname] [-s | --strip-all] [-S | -g | --strip-debug] [-N symbolname | --strip-symbol=symbolname] [-o file] [-p |--preserve-dates] [--help] objfile ... Description sdstrip discards all symbols from the object files objfile. The list of object files may include archives. At least one object file must be specified. sdstrip modifies the files named in its argument, rather than writing modified copies under different names. Options
sdstrip
6-5
Table 6.4
Option --help
sdstrip Options
Description Shows a summary of the options to strip and exit. Removes the named section from the file. You may give this option more than once. Note that using this option inappropriately may make the object file unusable. Removes any section named sectionname from the output file. You may give this option more than once. Note that inappropriate use of this option inappropriately may make the output file unusable. Removes all symbols. Removes debugging symbols only. Removes symbol symbolname from the source file. You may give this option more than once, and may be combined with other strip options. Puts the stripped output in file, rather than replacing the existing file. If you use this argument, you can specify only one objfile argument.
-R sectionname | --remove-section=sectionname -R sectionname | --remove-section=sectionname
-s | --strip-all -S | -g | --strip-debug -N symbolname | --strip-symbol=symbolname -o file
6-6
Utilities
6.3 sdranlib
Format sdranlib archive Description The sdranlib utility generates an index to the contents of an archive and stores it in the archive. The index lists each symbol defined by a member of an archive that is a relocatable object file. You may use `sdnm -s' or `sdnm --print-armap' to list this index. An archive with such an index speeds up linking to the library and allows routines in the library to call each other without regard to their placement in the archive.
sdranlib
6-7
6.4 sdnm
Format sdnm [-g | -s | -A | -o | -u | -l ] objfile
Description The sdnm utility lists the symbols from object files objfile. If no object files are given as arguments, sdnm assumes the file a.out. Options Table 6.5
Option -A | -o | --print-file-name
sdnm Options
Description Precedes each symbol by the name of the input file where it was found, rather than identifying the input file once only before all of its symbols. Displays only external symbols. Prints the symbols in the order they are encountered rather than sorting them first. When listing symbols from archive members, includes the index, which is a mapping (stored in the archive by ar or ranlib) of what modules contain definitions for what names. Uses radix as the radix for printing the symbol values. It must be `d' for decimal, `o' for octal, or `x' for hexadecimal. Displays only undefined symbols (those external to each object file). Uses debug information to display filename and line number for symbols.
-g | --extern-only -p | --no-sort -s | --print-armap
-t radix | --radix=radix -u | --undefined-only -l | --line-numbers
6-8
Utilities
6.5 sdsize
Format sdsize [ -A |B | --format=compatibility ][ -x | -radix=number ][ objfile... ] Description The sdsize utility lists the section sizes, and the total size, for each of the object or archive files objfile in its argument list. By default, one line of output is generated for each object file or each module in an archive. objfile... are the object files to be examined. If none are specified, the file a.out will be used. Options Table 6.6
Option -A | -B | --format=compatibility
sdsize Options
Description Using one of these options, you can choose whether the output from sdsize resembles output from System V UNIX size (using `-A', or `--format=sysv'), or Berkeley Software Distribution (BSD) size (using `-B', or `-format=berkeley'). The default is the one-line format similar to BSD format. Shows a summary of acceptable arguments and options. Using one of these options, you can control whether the size of each section is given in decimal (`-d', or `-radix=10'); octal (`-o', or `--radix=8'); or hexadecimal (`-x', or `--radix=16'). In `--radix=number', only the three values (8, 10, 16) are supported.
--help -d | -o | -x | --radix=number
Example Here is an example of formatting the output from sdsize closer to System V conventions: sdsize --format=SysV file1 file1 :
sdsize
6-9
section .text .data .bss Total
size 294880 81920 11592 388392
addr 8192 303104 385024
6-10
Utilities
6.6 sdstrings
Format sdstrings [-min-len] [-n min-len] [-t radix] [--print-file-name] [--bytes=min-len][--radix=radix] file... Description For each file given, the sdstrings utility prints the printable character sequences that are at least 4 characters long (or the number given with the options below) and are followed by an unprintable character. By default, only strings from the initialized and loaded sections of object files are printed; for other types of files, it prints the strings from the entire file. sdstrings is mainly useful for determining the contents of nontext files. Options Table 6.7
Option -f | --print-file-name -min-len | -n min-len | --bytes=min-len -t radix | --radix=radix
sdstrings Options
Description Prints the name of the file before each string. Prints sequences of characters that are at least min-len characters long, instead of the default 4. Prints the offset within the file before each string. The single character argument specifies the radix of the offset:`o' for octal, `x' for hexadecimal, or `d' for decimal.
sdstrings
6-11
6.7 sdobjdump
Format sdobjdump [ -d | --disassemble ] [ -f | --file-headers ] [ -j section | --section=section ] [ -t | --syms ] [ -h | --section-headers ] [ --start-address=address ] [ --stop-address=address ] [ --help ] objfile... Description The sdobjdump utility displays information about one or more object files. The options control what particular information to display. This information is most useful to programmers who are working on the compilation tools, as opposed to programmers who just want their program to compile and work. objfile... are the object files to be examined. When you specify archives, objdump shows information on each of the member object files. Options The long and short forms of options, shown here as alternatives, are equivalent. At least one option from the list must be given.
6-12
Utilities
Table 6.8
Option
sdobjdump Options
Description Displays the assembler mnemonics for the machine instructions from objfile. This option only disassembles those sections which are expected to contain instructions. Displays summary information from the overall header of each of the objfile files. Displays summary information from the section headers of the object file. You may relocate file segments to nonstandard addresses, for example by using the -Ttext, -Tdata, or -Tbss options to ld. Prints a summary of the options to objdump and exit Displays information only for named section. Starts displaying data at the specified address. This affects the output of the -d, -r and -s options. Stops displaying data at the specified address. This affects the output of the -d, -r and -s options. Prints the symbol table entries of the file. This is similar to the information provided by the `nm' program.
-d | --disassemble
-f | --file-header -h | --section-header | --header --help -j name | --section=name --startaddress=address --stop-address=address -t | --syms
sdobjdump
6-13
6.8 sdobjcopy
Format sdobjcopy [ -O bfdname | --output-target=bfdname ] [ -b byte | --byte=byte ] [ -i interleave | --interleave=interleave ] [ --gap-fill=val ] [ --pad-to=address ] [ --set-start=val ] [ --adjust-start=incr ] infile [outfile] Description The sdobjcopy utility copies the contents of an object file to another object file. It uses the GNU BFD Library to read and write the object files. It can write the destination object file in a format different from that of the source object file. The exact behavior of sdobjcopy is controlled by command-line options. sdobjcopy generates S-records if you specify an output target of `srec' (use `-O srec'). sdobjcopy generates binary output if you specify an output target of `binary' (use `-O binary'). sdobjcopy generates a raw binary file if you specify an output target of `binary' (e.g., use `-O binary'). When sdobjcopy generates a raw binary file, it will essentially produce a memory dump of the contents of the input object file. All symbols and relocation information will be discarded. The memory dump will start at the load address of the lowest section copied into the output file. When generating an S-record or a raw binary file, it may be helpful to use `-S' to remove sections containing debugging information. In some
6-14
Utilities
cases `-R' will be useful to remove sections which contain information which is not needed by the binary file. infile outfile The source and output files, respectively. If you do not specify outfile, objcopy creates a temporary file and destructively renames the result with the name of infile. Options Table 6.9
Option -O bfdname | --output-target=bfdname -b byte | --byte=byte
sdobjcopy Options
Description Write the output file using the object format bfdname. Keep only every byteth byte of the input file (header data is not affected). byte can be in the range from 0 to interleave-1, where interleave is given by the -i or --interleave option, or the default of 4. This option is useful for creating files to program ROM. It is typically used with an srec output target. Copy only one out of every interleave bytes. Select which byte to copy with the -b or --byte option. The default is 4. objcopy ignores this option if you do not specify either -b or --byte. Fill gaps between sections with val. This operation applies to the load address (LMA) of the sections. It is done by increasing the size of the section with the lower address, and filling in the extra space created with val. Pad the output file up to the load address address by increasing the size of the last section. The extra space is filled in with the value specified by --gap-fill (default zero). Set the address of the new file to val. Not all object file formats support setting the start address.
-i interleave | -interleave=interleave --gap-fill val
--pad-to address
--set-start val
sdobjcopy
6-15
6-16
Utilities
Chapter 7 ZISIM Simulator
This chapter describes the SDK ZSP architecture simulator. The ZSP SDK functional-accurate simulator, ZISIM, simulates the behavior of the LSI40xZ series of ZSP devices, ZSP400, and ZSPG2 architecture-based designs at the architectural level, including the memory model, the operand register file, and the control register file.
7.1 Using ZISIM
ZSIM can be accessed as a target through the debugger or as a standalone program. This chapter describes the interface to ZISIM as a standalone program. ZISIM can be used in batch mode or interactively, as described in the following subsections. The commands supported in both modes of operation are described in Section 7.2, "ZISIM Commands," page 7-4.
7.1.1 Batch Mode
The simulator can be invoked in batch mode from the command line using the -exec option, as shown below. % zisim400 executeable_file -exec [options] for ZSP400 architecture % zisimg2 executable_file -exec [options] for ZSPG2 architecture The simulator can also be invoked in batch mode using a script file containing ZSIM commands that load, execute, and gather results for a specified executable. Script files may contain any valid ZISIM commands. Comments must be preceded by the comment specifier (#). ZISIM ignores all commands between the # character and the end of line. ZISIM also ignores empty lines.
ZSP SDK Software Development Kit
7-1
A simple script file that turns-on instruction tracing and then executes the program test.exe is shown below. load test.exe enable trace write run 100000 exit Assuming the file batch.scr contains the commands shown above, you can generate a trace file for test.exe as follows: % zisim400 -s batch.scr > test.trace (Unix for ZSP400 architecture) % zisimg2 -s batch.scr > test.trace (Unix for ZSPG2 architecture) C:\zisim400 -s batch.scr > test.trace (Windows for ZSP400 architecture) C:\zisimg2 -s batch.scr > test.trace (Windows for ZSPG2 architecture) Refer also to Section 7.2.21, "script," page 7-15.
7.1.2 Interactive Mode
In interactive mode, ZISIM is invoked from the shell using the following command: zisim400 [executable_file] [options] zisimg2 [executable_file] options An executable file may or may not be specified, followed by zero or more command-line options separated by spaces The executable file is a ZSP binary file generated using the SDK compiler, assembler, and linker tools, as explained in other chapters of this document. ZISIM processes the source file according to the specified command-line options (refer to Table 7.1). If no options are specified, ZISIM initializes itself, then prompts the user with the ZISIM prompt: zisim{1}> The simulator is now ready to accept and respond to ZISIM commands, which are described in Section 7.2, "ZISIM Commands,". An executable file may be loaded from within ZISIM using the load exe command.
7-2
ZISIM Simulator
An example interactive simulation session is described in Section 7.4, "Example Session Using ZISIM". Refer also to the description of using ZISIM use as the target of the SDK's Debugger in Section 9.2.1, "Functional-Accurate Simulator Connection." Table 7.1
Option -c NUM
ZISIM Command-line Options
Description Limits number of executed instructions to NUM. By default, NUM = 2000000000. Execution continues until a breakpoint is reached or the number of executed instructions hit the limit. Use this option to ensure termination of an algorithm. Prints brief usage summary. Initializes an architectural control (mode) register with specified value. Note that the control register is written without its usual percent (%) sign, and there are no spaces around the equal sign (=). For example, the option to set %SMODE control register is: -i smode=0x1234. The option to set r0 register is -i r0=0x9876. Refer to Appendix B, "ZSP400 Control Registers" for information on ZSP400 core-based device control registers. Enables memory trace. ZISIM prints a trace of the execution program to standard output whenever a write to a memory occurs. The format of this output is similar to option -t. Fetches instructions from external ROM space. If you do not specify this option, instructions are fetched from internal ROM space. ROM is mapped from 0xf800 to 0xffff. This option is specific to zisim400. Displays data in specified radix, either decimal or hexadecimal. Enables register trace. All the architectural registers will be displayed after executing an instruction. Reads all the simulator commands from file. Enables flow trace. ZISIM prints a trace of the executing program to standard output. The information printed includes the instruction sequence number, instruction address, the disassembled instruction and operands, and the resulting architectural state. Example output for the -t option is shown in Section 7.4, "Example Session Using ZISIM," page 7-24. Invokes the simulator in noninteractive mode. Prints version number and exit.
-h -i mode_register=value
-m
-noiboot
-radix {dec|hex} -reg -s sourcefile -t
-exec -v
Using ZISIM
7-3
7.2 ZISIM Commands
This section describes commands recognized by the ZISIM command line. Table 7.2 provides a brief summary of commands. The output of any ZISIM command can be sent to a file using the standard redirection identifier (>). For example, the command show attr > filename dumps the output of the show command to filename. Table 7.2
Command alias clear
ZISIM Command Summary
Modifier - break dmem imem stats Argument [tag command_sequence] breakpoint_number {int | ext} addr size {int | ext} addr size - breakpoint {mem | reg | write} Description Creates alias (tag) for command sequence. Clears specified breakpoint. Clears internal or external data memory. Clears internal or external instruction memory. Clears statistics information. Disables specified breakpoint. Disables run-time instruction tracing.
disable
break trace
dump
dmem imem
{int | ext} filename addr size Dumps internal or external data memory range to a text file. {int | ext} filename addr size Dumps internal or external instruction memory range to a text file. breakpoint_number {mem | reg | write} - {int | ext} addr size value {int | ext} addr size value Enables breakpoint. Enables run-time instruction tracing. Exits simulation session. Fills internal/external data memory range with value. Fills internal/external instruction memory range with value.
enable
break trace
exit fill
- dmem imem
(Sheet 1 of 3)
7-4
ZISIM Simulator
Table 7.2
Command help load
ZISIM Command Summary (Cont.)
Modifier - dmem exe imem Argument {category | command} Description Prints list of commands in a category or command usage.
{int | ext} filename addr size Loads internal/external data memory from file. filename Loads ZSP executable into instruction memory from file.
{int | ext} filename addr size Loads internal/external instruction memory from file. {hard | soft} [number_of_instructions] filename {history | radix | run} value pc addr symbol label register value Resets simulator. Runs for specified number of simulation instructions. Loads and execute ZISIM script file. Assigns value to specified attribute. Creates a new breakpoint at the specified PC address. Creates a new breakpoint at the specified label. Assigns value to specified register.
reset run script set
- - - attr break break reg
(Sheet 2 of 3)
ZISIM Commands
7-5
Table 7.2
Command show
ZISIM Command Summary (Cont.)
Modifier attr bits break dmem imem reg stats trace Argument Description
{run | history | radix | version} Shows value of the specified attribute. register - {int | ext} addr size {int | ext} addr size {category | reg}... [opcode] - - alias Displays the bit-level states for the specified register. Displays list of defined breakpoints. Shows contents of a region of internal/external data memory. Shows contents of a region of internal/external instruction memory. Shows contents of register or register set. Shows current run-time statistics. Shows trace information during simulation. Advances simulation by one instruction. Same as run 1. Deletes alias.
step unalias
- -
(Sheet 3 of 3)
Table 7.3
Command set
ZISIM400 specific commands
Modifier Argument size [dmem|imem] size Description Set internal instruction or internal data memory size starting from 0. Default size is maximum value of 0xf800 words. Show size of internal instruction or data memory
show
size
[dmem|imem]
7-6
ZISIM Simulator
Table 7.4
Command set
ZISIMG2 specific commands
Modifier size Argument [dmem|imem] [int|ext] beg_value end_value Description Set the size of internal/external instruction or data memory starting from beg_value to end_value including the boundary. Each memory block could overlap one another. Default value for each of them is from 0 to 0x00ffffff words. Show the current size of internal/external instruction or data memory.
show
size
[dmem|imem] [int|ext]
7.2.1 alias
The alias command allows the user to create ZISIM commands by aliasing new commands to existing commands or sequences of commands. Sequences of commands must be contained in quotes and separated by semicolons. Issuing the alias command without arguments shows all current aliases. Format alias tag command_sequence
ZISIM Commands
7-7
Examples zisim{32} alias r0 show reg r0 zisim{32} alias adv "step ; show pipe ; show reg gpr" zisim{32} alias adv step ; show pipe ; show reg gpr r0 show reg r0 zisim{33}
7.2.2 clear break
This command deletes a breakpoint from the current list of defined breakpoints. The breakpoint number is assigned when a breakpoint is set. Use the show break command to display a list of breakpoints. Format clear break breakpoint_number Example zisim{32} clear break 5
7.2.3 clear dmem
This command clears the contents of internal or external data memory. User specifies internal or external memory, the starting address, and the size of the region to clear. Format clear dmem {int|ext} addr size Example zisim{32} clear dmem int 0x1000 0x0100
7.2.4 clear imem
This command clears the contents of internal or external instruction memory. User specifies internal or external memory, the starting address, and the size of the region to clear. Format clear imem {int|ext} addr size
7-8
ZISIM Simulator
Example zisim{32} clear imem ext 0x7000 0x1000
7.2.5 clear stats
This command clears all run-time statistic information. Format clear stats
7.2.6 disable break
This command disables a breakpoint from the list of active breakpoints. Use the show break command to display a list of current breakpoints. Format disable break breakpoint_number Example zisim{32} disable break 4
7.2.7 disable trace
This command disables specified trace. See the enable trace command for a description of the trace types. Format disable trace {mem|reg|write} Examples zisim{32} disable trace pipe zisim{32} disable trace reg
7.2.8 dump dmem
This command generates a text file representing the contents of the specified address range of internal or external data memory. The user specifies internal or external memory, the starting address, and the size of the region to dump.
ZISIM Commands
7-9
Format dump dmem {int|ext} filename addr size Example zisim{32} dump dmem ext data.dat 0x0000 0xffff % cat data.dat 0000 /* 0x0000 */ 0000 /* 0x0001 */ 0000 /* 0x0002 */ 0000 /* 0x0003 */ 0000 /* 0x0004 */ 0000 /* 0x0005 */ 0000 /* 0x0006 */ ... 28e2 /* 0x00fd */ 2f6a /* 0x00fe */ 325d /* 0x00ff */ %
7.2.9 dump imem
This command generates a text file representing the contents of the specified address range of internal or external instruction memory. The user specifies internal or external memory, the starting address, and the size of the region to dump. Format dump imem {int|ext} filename addr size Example zisim{32} dump imem int imem.dat 0x1000 0x30 % cat imem.dat 0000 /* 0x1000 0000 /* 0x1001 0000 /* 0x1002 0000 /* 0x1003 ... 0000 /* 0x102c 0000 /* 0x102d 0000 /* 0x102e 0000 /* 0x102f %
*/ */ */ */ */ */ */ */
7-10
ZISIM Simulator
7.2.10 enable break
This command enables a breakpoint from the current list of defined breakpoints. Use the show break command to display a list of current breakpoints. Format enable break breakpoint_number Example zisim{32} enable break 1
7.2.11 enable trace
This command enables a predefined trace type. There are three types of predefined run-time tracing. Run-time traces generate text output instruction by instruction. The three trace types are:
*
mem Displays address and data for any memory location which is updated. Information is generated after the instruction is executed.
* *
reg Displays all registers and register values every instruction. write Displays architectural state changes associated with memory or registers for each instruction.
Format enable trace {mem|reg|write} Example zisim{32} enable trace write
7.2.12 exit
This command terminates the current simulation session. Format exit
ZISIM Commands
7-11
7.2.13 fill dmem
This command fills internal or external data memory range with specified value. User specifies internal or external memory, the starting address, and the size of the region to fill. Format fill dmem {int|ext} addr size value Example zisim{32} fill dmem ext 0x1000 0xff 0x0505
7.2.14 fill imem
This command allows you to specify internal or external memory, the starting address, and the size of the region to fill. Format fill imem {int|ext} addr size value Example zisim{32} fill imem ext 0x1000 0xff 0x0505
7.2.15 help
This command displays help information. Help is available for individual commands as well as for command categories. Specifying a command displays the description and usage for that command. Requesting help for a specified category displays the instructions associated with that category. Commands are categorized according to their function (for instance, all show commands). Issuing the help command with no other specifiers displays help on the command categories. Format help [category|command] Examples zisim{32} help
7-12
ZISIM Simulator
zisim{32} help all zisim{32} help show zisim{32} help show reg
7.2.16 load dmem
This command loads internal or external data memory from specified text file. User specifies internal or external memory, the starting address, and the size of the region to load. The format of the text file should be the same as the file produced by the dump command. The first column contains the data that will be loaded, with each data on a single line. Data must be in hex format with out 0x prefix. Comments must be enclosed by `/* */ '. Format load dmem {int|ext} filename addr size Example zisim{32} load dmem int data.dat 0x1000 0x0fff The output format of the file is: %cat data.dat 2ce5 /* 0x0000 3c3f /* 0x0001 2000 /* 0x0002 3006 /* 0x0003 a00f /* 0x0004 80c0 /* 0x0005 ... */ */ */ */ */ */
7.2.17 load exe
This command loads a valid ZSP executable into instruction memory. This command performs the same function as specifying the executable filename when ZISIM is invoked. Without the filename specified, this command reloads the previous executable program into memory. Format load exe {filename}
ZISIM Commands
7-13
Example zisim{32} load exe test.exe or zisim{32} load test.exe
7.2.18 load imem
This command loads internal or external instruction memory from specified text file. You must specify internal or external memory, the starting address, and the size of the region to load. You must ensure that the format of the text file is the same as the file produced by the dump command. The first column contains the data that will be loaded, with each data on a single line. Data must be in hex format without the 0x prefix. Comments must be enclosed by `/* */ '. Format load imem {int|ext} filename addr size Example % cat inst.txt 2ce5 /* 0x0000 3c3f /* 0x0001 2000 /* 0x0002 3006 /* 0x0003 a00f /* 0x0004 80c0 /* 0x0005 bc4c /* 0x0006 6f4c /* 0x0007 */ */ */ */ */ */ */ */
zisim{32} load imem int inst.txt 0x1000 8
7.2.19 reset
This command resets the state of the simulator. A soft reset initializes all aspects of the simulator except the memory. A hard reset also initializes memories. Issuing the reset command without options performs a soft reset. Format reset [soft|hard]
7-14
ZISIM Simulator
Examples zisim{32} reset soft zisim{32} reset hard Note that the reset command does not reload the program into memory. In order to restart the program, perform one of the following sequence of commands: zisim{32} reset zisim{32} set reg pc or zisim{32} reset hard; load zisim{33} load Note: zisimg2 doesn't support reset soft feature.
7.2.20 run
This command advances the simulator the specified number of instructions. The simulator uses the value of the run attribute if no instruction count is specified. Simulation halts if instruction count is reached, the maximum instruction count is reached, or a system halt occurs. Format run [number_of_instructions] Examples zisim{32} run zisim{32} run 100
7.2.21 script
This command loads and processes the script file. Script files may contain any valid ZISIM commands. Comments are allowed in the script file; the comment specifier is the # character. ZISIM ignores all commands between the # character and the end of line. Empty lines are also ignored. Format
ZISIM Commands
7-15
script filename Example zisim{32} script standard.scr Sample Script File A simple script is shown below. # This example script demonstrates how to turn on # instruction tracing using a command. load test.exe enable trace write run exit
7.2.22 set attr
The set attr command allows you to set three internal ZISIM variables. Table 7.5 shows the configurable ZISIM attributes. Table 7.5
Attribute history radix run
Configurable ZISIM Attributes
Value any integer [int | hex] any integer Description Number of commands to maintain in history buffer. Radix (integer or hexadecimal) used to generate output. Default instruction count for the run command (when issuing the run command with no argument). If undefined, the default value of the run attribute is 2000000000.
Format set attr [history|radix|run] value Examples zisim{32} set attr run 1000 zisim{32} set attr radix hex
7-16
ZISIM Simulator
7.2.23 set break
This command creates and enables a new breakpoint at specified address. Execution halts when the PC reaches the specified address. When a new breakpoint is created, ZISIM tags it with a breakpoint number which is used for other breakpoint commands (use the show break command to view a list of current breakpoints). Format set break pc addr set break symbol label Example zisim{2} set Breakpoint 1 zisim{3} set Breakpoint 2 break on PC break on PC pc 0x0010 at address 0x0010 symbol main at address 0xf9b9 of main
7.2.24 set reg
This command assigns a value to the specified register. Format set reg register value Example zisim{32} set reg r0 0x1234
7.2.25 set size
7.2.25.1 zisim400 This command sets the size of internal data memory or instruction memory. The default size of internal data or instruction memory is 63488 words (62K words), which is also the maximum size that can be set. This command does not apply to external memory. (The simulator has 1M words for each external instruction and external data memory.) Format set size {dmem|imem} size
ZISIM Commands
7-17
Examples zisim{32} set size dmem 0x4000 This command sets the size of internal data memory to 16 Kwords. zisim{32} set size imem 0x4000 This command sets the size of internal instruction memory to 16 Kwords 7.2.25.2 zisimg2 This command sets the size of internal/external data memory or instruction memory. The default size of internal/external data or instruction memory is 0xffffffwords (16M words) starting from 0, which is also the maximum size that can be set. This command does not apply to external memory. (The simulator has 1M words for each external instruction and external data memory.) Format set size {dmem|imem} {int|ext} beg_value end_value Examples zisim{32} set size dmem int 0 0xffff This command sets the size of internal data memory to 16 Kwords. zisim{32} set size imem int 0 0xffff This command sets the size of internal instruction memory to 16 Kwords. .
7.2.26 show attr
This command shows the value of the specified attribute. You can view the value of the three attributes which are configurable with the set attr command as well as view version information for ZISIM. Format show attr {run|history|radix|version} Example
7-18
ZISIM Simulator
zisim{1} zisim{2} zisim{3} zisim{4}
show show show show
attr attr attr attr
run history radix version
7.2.27 show bits
This command displays the bit field values for the specified register. Do not use the % specifier for control registers. Format show bits register Example zisim{32} show bits hwflag hwflag = 0x0000 er: 0 ex: 0 ir: 0 z: 0 gt: 0 ge: 0 c: 0 gsv: 0 sv: 0 gv: 0 v: 0
7.2.28 show break
This command displays the list of currently defined breakpoints. Format show break Example zisim{32} show break Num ID Address Status ----------------------2 PC 0x2000 Active 1 PC 0xf9b9 Active
ZISIM Commands
7-19
7.2.29 show dmem
This command displays a range of internal or external data memory. You must specify internal or external memory, the starting address, and the size of the region to display. The default settings for the show dmem command are shown in Table 7.6. Table 7.6
Argument {int | ext} addr size
Default Arguments for show dmem
Value int 0x0 16
Format show dmem {int|ext} addr size Example zisim{32} show dmem int 0xf000 0x10 For zisimg2, user can use a symbol instead of an absolute address value. zisim{1} show dmem int array1 20
7.2.30 show imem
This command displays a range of internal or external instruction memory. User specifies internal or external memory, the starting address, and the size of the region to show. The size and addr fields may be omitted, in which case defaults are used. The default settings for the show imem command are shown in Table 7.7. Table 7.7
Argument {int | ext} addr size
Default Arguments for show imem
Value int 0x0 16
7-20
ZISIM Simulator
Format show imem {int|ext} [addr] [size] Example zisim{32} show imem int 0xf000 0x10 For zisimg2, user can use a symbol instead of an absolute address value. zisim{1} show imem int foo_function 20
7.2.31 show reg
This command displays the value of a specified register or the value of a category of registers. More than one category and/or register can be specified. The register categories are:
* *
gpr All general purpose registers, r0-r15. cfg All control registers (such as %smode and %hwflag). Do not include the percent sign (%) in the register name.
*
addr All address and index registers for the ZSPG2 architecture. Thus, it is specific for zisimg2.
Format show reg {category|register} ... Examples zisim{32} zisim{32} zisim{32} zisim{32} show show show show reg gpr cfg r0 gpr hwflag smode
ZISIM Commands
7-21
7.2.32 show size
7.2.32.1 zisim400 This command shows the size of internal data or instruction memory. The output is not affected by the radix attribute. Format show size {dmem|imem} Examples zisim{32} show size dmem zisim{32} show size imem 7.2.32.2 zisimg2 This command shows the size of internal/external data or instruction memory. The output is not affected by the radix attribute. Format show size {dmem|imem}{int|ext} Examples zisim{32} show size dmem int zisim{32} show size imem int
7.2.33 show stats
This command displays run-time statistics collected by ZISIM. If no argument is specified, ZISIM displays overall statistical information. If the opcode argument is specified, ZISIM displays instruction opcode statistics. Format show stats [opcode] Examples zisim{32} show stats zisim{32} show stats opcode
7-22
ZISIM Simulator
7.2.34 show trace
This command shows currently enabled/disabled trace information. Traces currently set to ON are enabled during simulation. Format show trace Example zisim{32} show trace ***(info) Supported trace information: - Instruction trace: OFF - Register trace: OFF - Memory trace: OFF zisim{33}> enable trace write ***(info) Instruction trace is ON. zisim{34}> show trace ***(info) Supported trace information: - Instruction trace: ON - Register trace: OFF - Memory trace: OFF
7.2.35 step
This command single-steps the simulator. Issuing the step command is equivalent to issuing the command run 1. Format step Example zisim{32} step
7.2.36 unalias
This command deletes an alias. (Use the alias command to display a list of currently defined aliases.) Format unalias alias Example
ZISIM Commands
7-23
zisim{32} unalias adv
7.3 I/O Port Usage
ZISIM400 models serial I/O as a memory-mapped device. Programs perform terminal I/O by reading from and writing to the appropriate address locations. The simulator defines two serial ports and one host processor interface (HPI) port. Each port has a transmit buffer and a receive buffer. Table 7.8 shows the memory addresses and corresponding files for the I/O ports for the LSI402ZX, LSI403Z, and ZSP400-core based devices. Table 7.8 I/O Device Memory Map and Associated Files
Read I/O Port Serial Port 0 Serial Port 1 Host Interface Port Address 0xF901 0xFA01 0xFB01 File sp0in sp1in hpiin Address 0xF900 0xFA00 0xFB00 Write File sp0out sp1out hpiout
The format of input and output files is the same. Data must be in decimal digits, with each data on a single line. If the input file is not present in the current running directory at the time of the request, the simulator will print an error message to standard output and exit.
7.4 Example Session Using ZISIM
This section contains an example simulation session using ZISIM in interactive mode. In the example simulation, demo.exe is invoked using the -t (enable trace) command-line option. Trace information is displayed in five fields:
(0) 0x2000 2cfb movl r12, 0xfb ! r12 = 0x00fb
*
The first field is the instruction sequence number (in parenthesis).
7-24
ZISIM Simulator
* * * *
The second field is the program counter (PC) of the executed instruction. The third field is the instruction opcode. The fourth field is the disassembled instruction, including operands. The fifth field describes the result of the executed instruction.
The trace shown in this example is for the ZSP400 core. The text is linked and loaded at 0x2000.
Example Session Using ZISIM
7-25
(shell prompt) zisim400 demo.exe -t ************************************************* ZISIM 1.206 ZSP400 Instruction Set Simulator LSI Logic ************************************************* ***(info) Starting address: 0x2000 .text : Loading to INT-INST memory ... 0x2000 -> 0x2950 (0x0951) .data : Loading to INT-DATA memory ... 0x0001 -> 0x005f (0x005f) Loading "demo.exe" successfully. zisim{1}_
If you do not specify a test for initialization, you can load a test from the ZISIM command line. Check the contents of the instruction memory to confirm proper loading of the test. These steps are demonstrated below.
zisim{1}show imem int 0x2000 4 0x2000 0x2cfb movl r12, 0xfb 0x2001 0x3cf7 movh r12, 0xf7 0x2002 0xa6d0 mov r13, 0x0 0x2003 0x2460 movl r4, 0x60 zisim{2}> _
Instruction fetch begins at the entry point you specify in an executable program. You can change this before execution begins by setting the PC to the desired value using the set reg command. The simulator output below demonstrates use of the PC breakpoint: a breakpoint is set for address 0x10 and the simulator advances until the PC reaches address 0x10.
7-26
ZISIM Simulator
zisim{3}> set break pc 0x2050 Breakpoint 1 on PC at address 0x2050 zisim{4}> set break symbol main Breakpoint 2 on PC at address 0x2010 of main zisim{5}> run (0) 0x2000 2cfb movl r12, 0xfb ! r12 = 0x00fb (1) 0x2001 3cf7 movh r12, 0xf7 ! r12 = 0xf7fb (2) 0x2002 a6d0 mov r13, 0x0 ! r13 = 0x0000 (3) 0x2003 2460 movl r4, 0x60 ! r4 = 0x0060 (4) 0x2004 3400 movh r4, 0x0 ! r4 = 0x0060 (5) 0x2005 bc54 mov r5, r4 ! r5 = 0x0060 (6) 0x2006 a051 add r5, 0x1 ! hwflag = 0x0030 (6) 0x2006 a051 add r5, 0x1 ! r5 = 0x0061 (7) 0x2007 6054 st r5, r4, 0 ! INT-DATA[0x0060] = 0x0061 (8) 0x2008 bb1d mov rpc, r13 ! rpc = 0x0000 (9) 0x2009 2510 movl r5, 0x10 ! r5 = 0x0010 (10) 0x200a 3520 movh r5, 0x20 ! r5 = 0x2010 (12) 0x200c a750 call r5 ! rpc = 0x200d (PC BREAKPOINT #2)................ Instruction Count=000013 PC=0x2010 zisim{6}> show reg gpr r0 = 0x0000 r1 = 0x0000 r2 = 0x0000 r3 = 0x0000 r4 = 0x0060 r5 = 0x2010 r6 = 0x0000 r7 = 0x0000 r8 = 0x0000 r9 = 0x0000 r10 = 0x0000 r11 = 0x0000 r12 = 0xf7fb r13 = 0x0000 r14 = 0x0000 r15 = 0x0000 zisim{7}> disable trace write
After the final command, the simulator will no longer print the instruction flow trace.
zisim{8}> run Hello World! (SYSTEM HALT)..................... Instruction Count=000673 PC=0x200e
Execution halts when a breakpoint is reached, a system halt occurs, or the maximum instruction count is reached. A system halt refers to setting halt mode as defined by the %smode control register. Execution statistic information can be seen by using show stats command.
zisim{9}> 673 88 65 23 56 37 19 show stats instructions executed load instructions ( 13.08%) - single ( 9.66%) - double ( 3.42%) store instructions ( 8.32%) - single ( 5.50%) - double ( 2.82%)
Example Session Using ZISIM
7-27
104 15 63 10 25
discontinuities - calls - conditional - agnx mispredicts
( 15.45%) ( 2.23%) ( 9.36%) ( 1.49%) ( 39.68% of conditional branch)
Terminate the simulation session with the exit command.
zisim{10}> exit ***(info) Exiting ZISIM.
7-28
ZISIM Simulator
Chapter 8 ZSIM Simulator
This chapter describes the ZSP SDK cycle-accurate architecture simulator. The ZSP SDK simulator ZSIM is a cycle-accurate simulator for ZSP400 and ZSPG2 architecture-based devices. ZSIM models the architectural features necessary for cycle-by-cycle tracing of architectural state, including the execution pipeline, instruction and data caches, internal and external instruction/data memories, and register files.
8.1 Using ZSIM
ZSIM can be accessed as a target through the debugger or as a standalone program. This chapter describes the interface to ZSIM as a standalone program. ZSIM can be used in batch mode or interactively, as described in the following subsections. The commands supported in both modes of operation are described in Section 8.2, "ZSIM Commands," page 8-5.
8.1.1 Batch Mode
The simulator can be invoked in batch mode from the command line using the -exec option, as shown below. % zsim[400/g2] executeable_file -exec [options] The simulator can also be invoked in batch mode using a script file containing ZSIM commands that load, execute, and gather results for a specified executable. Script files may contain any valid ZSIM commands. Comments are allowed and must be preceded by the comment specifier (#). ZSIM ignores all commands between the # character and the end of line. ZSIM also ignores empty lines.
ZSP SDK Software Development Kit
8-1
A simple script file that turns on instruction tracing and then executes the program test.exe is shown below. load test.exe enable trace write run 100000 exit Assuming the file batch.scr contains the commands shown above, a trace file for test.exe could be generated as follows: % zsim400 -s batch.scr > test.trace (Unix for ZSP400 architecture) % zsimg2 -s batch.scr > test.trace (Unix for ZSPG2 architecture) C:\zsim400 -s batch.scr > test.trace (Windows for ZSP400 architecture) C:\zsimg2 -s batch.scr > test.trace (Windows for ZSPG2 architecture) Refer also to Section 8.2.26, "script," page 8-21.
8.1.2 Interactive Mode
In interactive mode, ZSIM is invoked from the command line using the following command: For ZSP400 architecture: zsim400 [executable_file] [options] For ZSPG2 architecture: zsimg2 [executeable_file] [options] You may optionally specify an executable file, followed by zero or more command-line options, which must be separated by spaces The executable file is a ZSP binary file generated using the SDK compiler, assembler, and linker tools, as explained in other chapters of this document. ZSIM processes the source file according to the specified command-line options (refer to Table 8.1). If no options are specified, ZSIM initializes itself, then prompts the user with the ZSIM prompt:
8-2
ZSIM Simulator
zsim{1}> The simulator is now ready to accept and respond to ZSIM commands, which are described in Section 8.2, "ZSIM Commands" on page 8-5. An executable file may be loaded from within ZSIM using the load exe command. An example interactive simulation session is described in Section 8.4, "Example Session Using ZSIM" on page 8-34. Refer also to the description of using ZSIM use as the target of the SDK's Debugger in Section 9.2.2, "Cycle-Accurate Simulator Connection," page 9-4. Table 8.1
Option -exec -c num -h
ZSIM Command-line Options
Description Invokes the simulator in noninteractive mode. Specifies maximum cycle count. Execution aborted after num cycles. Prints brief usage summary.
-i mode_register=value Initializes an architectural control (mode) register with specified value. The control register is written without its usual percent (%) sign, and there are no spaces around the equal sign (=). For example, the option to set %smode control register is: -i smode=0x1234. The option to set r0 register is -i r0=0x9876. Refer to Appendix B, "ZSP400 Control Registers" for information on ZSP400 core-based device control registers or Appendix D"ZSPG2 Control Registers" -m -p -pf -pfiu -pfpipe (Sheet 1 of 2) Turns on memory trace. Turns on pipeline trace. Turns on all profile information. Turns on instruction unit profile information. Turns on pipeline unit profile information.
Using ZSIM
8-3
Table 8.1
Option -q
ZSIM Command-line Options (Cont.)
Description Suppresses startup banner. Displays data in the specified radix, either decimal (dec) or hexadecimal (hex). Turns on register trace. Executes the specified script file following initialization. Turns on instruction trace. Prints ZSIM version number.
-radix {dec | hex} -reg -s sourcefile -t -v (Sheet 2 of 2)
Table 8.2
Options -wed num -wei num -sid num -sii num -mempcr num -nomempcr -noiboot
Command-line Options for zsim400
Description Sets EXT-DATA memory wait state to be num. Default is 1. Sets EXT-INST memory wait state to be num. Default is 1. Sets INT-DATA memory size to be num. Default is 63488 words. Sets INT-INST memory size to be num. Default is 63488 words. Sets the MEMPCR address to be num. Default is 0xf807. Indicates that the system does not have MEMPCR. Sets the IBOOT signal LOW to boot from external ROM. If this option is not specified, instructions are fetched from internal ROM space. ROM is mapped from 0xf800 to 0xffff. Turns on data unit profile information.
-pfdu
8-4
ZSIM Simulator
Table 8.3
Options -pflsu -tic
Command-line Options for zsimg2
Description Turn on Load Store Unit profile information Turn on instruction cache trace every cycle Set system vector table address to be ADDR Use ideal memory subsystem with zero delay for internal memory and no checking for banking conflict between 2 data access ports. Use bus interface library LIBNAME to run in co-simulation enviroment such as SWIFT or CVE Seamless. Use co-processor library LIBNAME. SDK tools comes with an example G711 coprocessor library called libzcpig711.so on Solaris or libzcpig711.dll on Windows platform.
-svtadd ADDR -idealmss -bimlib LIBNAME -cpilib LIBNAME
8.2 ZSIM Commands
The ZSIM commands are described briefly in Table 8.4 and in detail in the following subsections. The output of any ZSIM command can be sent to a file using the standard redirection identifier (>). For example, the command show attr > mydisplay writes the output of the show command in the file mydisplay. Table 8.4
Command alias
ZSIM Command Summary
Modifier Argument - [tag command_sequence] Description Creates alias (tag) for command sequence.
(Sheet 1 of 4)
ZSIM Commands
8-5
Table 8.4
Command clear
ZSIM Command Summary (Cont.)
Modifier Argument break dmem icache imem stats breakpoint_number {int | ext} addr size - {int | ext} addr size - breakpoint_number [du | iu | pipe] {pipe | reg} Description Clears specified breakpoint. Clears internal or external data memory. Clears instruction cache. Clears internal or external instruction memory. Clears statistic information. Disables specified breakpoint. Disables profile information. Disables run-time tracing.
disable
break profile trace
dump
dmem imem
{int | ext} filename addr size Dumps internal or external data memory to a text file filename. {int | ext} filename addr size Dumps internal or external instruction memory to a text file filename. breakpoint_number {iu | pipe} Enables breakpoint. Enables module profile information.
enable
break profile trace
{mem | pipe | reg | write| icache} Enables run-time cycle tracing. - {int | ext} addr size value {int | ext} addr size value {category | command} Exits simulation session. Fills internal/external data memory segment with value. Fills internal/external instruction memory segment with value. Prints list of commands in a category or command usage. Advances the simulator by one instruction.
exit fill
- dmem imem
help istep
- -
(Sheet 2 of 4)
8-6
ZSIM Simulator
Table 8.4
Command load
ZSIM Command Summary (Cont.)
Modifier Argument dmem exe imem {int | ext} filename addr filename {int | ext} filename addr {hard | soft} [number_of_cycles] filename {history | radix | run} value pc addr symbol label register value Description Loads internal/external data memory from file. Loads ZSP executable into instruction memory. Loads internal/external instruction memory from file. Reset simulator (hard or soft). Runs for specified number of simulation cycles. Loads and executes ZSIM script file. Assigns value to specified attribute. Creates a new breakpoint at the specified PC address. Creates a new breakpoint at the specified label. Assigns value to specified register.
reset run script set
hard - - attr break break reg
(Sheet 3 of 4)
ZSIM Commands
8-7
Table 8.4
Command show
ZSIM Command Summary (Cont.)
Modifier Argument attr bits break dmem icache imem pipe profile reg rule size stats trace {history | radix | run | version} register - { int | ext} addr size - {int | ext} addr size - - {category | reg}... - {dmem | imem} - - - alias Description Shows value of the specified attribute. Displays the bit-level states for the specified register. Shows list of defined breakpoints. Shows contents of a region of internal/external data memory. Shows current instruction cache contents. Shows contents of a region of internal/external instruction memory. Shows contents and state of execution pipeline. Displays supported profile information. Shows contents of register or register set. Shows the affected grouping rule in the current cycle. Shows size of internal data or instruction memory. Shows current run-time statistics. Shows the current status of all tracing attributes. Advances simulation by one cycle. Same as run 1. Deletes alias.
step unalias
- -
(Sheet 4 of 4)
8-8
ZSIM Simulator
Table 8.5
Command clear set
ZSIM400 specific commands
Modifier dcache delay Argument [edata|einst] num Description Clear data cache. Sets wait state for external memory. Default for both external data and instruction memory is 1. Set internal instruction or internal data memory size starting from 0. Default size is maximum value of 0xf800 words. Show size of internal instruction or data memory Show data cache contents. Enable profile information on Data Unit. Disable profile information on Data Unit.
set
size
[dmem|imem] size
show show enable disable
size dcache profile profile
[dmem|imem] du du
ZSIM Commands
8-9
Table 8.6
Command set
ZSIMG2 specific commands
Modifier latency Argument [dmem|imem] [int|ext] num Description Set wait state latency for internal/external instruction or data memory. Default value for internal memory is 2 and external memory is 5. Show wait state latency for internal/external instruction or data memory. Set the size of internal/external instruction or data memory starting from beg_value to end_value including the boundary. Each memory block could overlap one another. Default value for each of them is from 0 to 0x00ffffff words. Show the current size of internal/external instruction or data memory. Show operand values of an instruction number. Instruction number can be obtained by looking at the output of "show pipe" command. Display the statistic of grouping rule. Turn on profile information of Load Store Unit. Turn off profile information of Load Store Unit.
show
latency
[dmem|imem] [int|ext]
set
size
[dmem|imem] [int|ext] beg_value end_value
show
size
[dmem|imem] [int|ext]
show
operands
instruction_number
show enable disable
stats profile profile
grouping lsu lsu
8-10
ZSIM Simulator
8.2.1 alias
This command creates an alias for a ZSIM command. This command allows you to customize the ZSIM commands by aliasing new commands to existing commands or sequences of commands. Sequences of commands must be contained in quotes and separated by semicolons. Issuing the alias command without arguments displays all current aliases. Format alias [tag] [command_sequence] Examples zsim{32} alias r0 show reg r0 zsim{32} alias adv "step ; show pipe ; show reg gpr" zsim{32} alias adv step ; show pipe ; show reg gpr r0 show reg r0 zsim{33}
8.2.2 clear break
This command deletes a breakpoint from the current list of defined breakpoints. The breakpoint number is assigned when a breakpoint is set. Use the show break command to display a list of breakpoints. Format clear break breakpoint_number Example zsim{32} clear break 5
8.2.3 clear dcache
This command invalidates the contents of the data cache. Format clear dcache
ZSIM Commands
8-11
Example zsim{32} clear dcache
8.2.4 clear dmem
This command clears the contents of internal or external data memory. User specifies internal or external memory, the starting address, and the size of the region to clear. Format clear dmem {int|ext} addr size Example zsim{32} clear dmem int 0x1000 0x0100
8.2.5 clear icache
This command clears the contents of the instruction cache. Format clear icache Example zsim{32} clear icache
8.2.6 clear imem
This command clears the contents of internal or external instruction memory. User specifies internal or external memory, the starting address, and the size of the region to clear. Format clear imem {int|ext} addr size Example zsim{32} clear imem ext 0x7000 0x1000
8-12
ZSIM Simulator
8.2.7 clear stats
This command clears all the run-time statistical information, which includes the cycle count, the number of executed instructions, and the number of instructions that are being grouped in the pipe. Format clear stats Example zsim{32} clear stats
8.2.8 disable break
This command disables a breakpoint from the current list of active breakpoints. (Use the show break command to display current list.) Format disable break breakpoint_number Example zsim{32} disable break 4
8.2.9 disable profile
This command disables specified type of profile information. If no profile type is specified, the command will disable all types. Profile types are described in Section 8.2.14, "enable profile," page 8-15. Format disable profile [du|iu|pipe] Examples zsim{32} zsim{32} zsim{32} zsim{32} disable disable disable disable profile du profile iu profile pipe profile
ZSIM Commands
8-13
8.2.10 disable trace
This command disables specified type of trace. Trace types are described in Section 8.2.15, "enable trace," page 8-16. Format disable trace type Examples zsim{32} disable trace pipe zsim{32} disable trace reg
8.2.11 dump dmem
This command generates a text file representing the contents of the specified address range of the internal or external data memory. The user specifies internal or external memory, the starting address, and the size of the region to dump. Format dump dmem {int|ext} filename addr size Example zsim{32} dump dmem ext data.dat 0x0000 0x100 % cat data.dat 0000 /* 0x0000 0000 /* 0x0001 0000 /* 0x0002 0000 /* 0x0003 0000 /* 0x0004 0000 /* 0x0005 0000 /* 0x0006 ... 28e2 /* 0x00fd 2f6a /* 0x00fe 325d /* 0x00ff %
*/ */ */ */ */ */ */ */ */ */
8.2.12 dump imem
This command generates a text file representing the contents of the specified address range of the internal or external instruction memory.
8-14
ZSIM Simulator
The user specifies internal or external memory, the starting address, and the size of the region to dump. Format dump imem {int|ext} filename addr size Example zsim{32} dump imem int imem.dat 0x1000 0x30 % cat imem.dat 0000 /* 0x1000 0000 /* 0x1001 0000 /* 0x1002 0000 /* 0x1003 ... 0000 /* 0x102c 0000 /* 0x102d 0000 /* 0x102e 0000 /* 0x102f %
*/ */ */ */ */ */ */ */
8.2.13 enable break
This command enables a breakpoint from the current list of defined breakpoints. See Section 8.2.28, "set break," page 8-23, for a description of how to create a breakpoint. Format enable break breakpoint_number Example zsim{32} enable break 1
8.2.14 enable profile
This command enables a predefined trace type. Run-time traces generate text output representing the state of the architecture on a cycleby-cycle basis. There are three types of predefined run-time tracing:
*
du Displays information from the data unit of the ZSP400 architecture, such as data cache hits and the du_imem_read signal.
ZSIM Commands
8-15
*
iu Displays information from the instruction unit, such as instruction cache hits and the iu_imem_read signal.
*
pipe Displays information from the pipeline unit, such as cycle-by-cycle grouping rule information.
*
lsu Displays information from the load/store unit of ZSPG2 architecture..
Format enable profile {du|iu|pipe|lsu} Examples zsim{1} enable profile du ***(info) Data Unit profile information is ON. zsim{2} enable profile iu ***(info) Instruction Unit profile information is ON. zsim{3} enable profile pipe ***(info) Pipeline Unit profile information is ON.
8.2.15 enable trace
This command enables a predefined trace type. Run-time traces generate text output representing the state of the architecture on a cycleby-cycle basis. There are four types of predefined run-time tracing:
*
mem Displays address and data for any memory location which is updated. Information is generated in the cycle in which the write occurs.
* * *
pipe Displays the entire pipeline in every cycle. reg Displays all registers and values in every cycle. write
8-16
ZSIM Simulator
Displays architectural state changes associated with memory or registers for each cycle. Format enable trace {mem|pipe|reg|write} Example zsim{32} enable trace write
8.2.16 exit
This command terminates the current simulation session. Format exit Example zsim{32} exit
8.2.17 fill dmem
This command fills internal or external data memory range with specified value. Format fill dmem {int|ext} addr size value Example zsim{32} fill dmem ext 0x1000 0xff 0x0505
8.2.18 fill imem
This command fills internal or external instruction memory range with specified value. Format fill imem {int|ext} addr size value Example zsim{32} fill imem ext 0x1000 0xff 0x0505
ZSIM Commands
8-17
8.2.19 help
This command displays help information about commands. Commands are categorized according to their function. Requesting help without specifiers displays help on the command categories; requesting help for a specified category displays the instructions associated with that category. Specifying a particular command displays the description and usage for that command. Format help [category|command] Examples zsim{32} zsim{32} zsim{32} zsim{32} help help all help show help show reg
8.2.20 istep
This command steps the program instruction by instruction. By default, this command is aliased to is. For zsimg2, user can specify a number to indicate number of instructions to be executed. Format istep or is Examples zsim{22}> istep CYCLE=000012 PC=0x200c 0x2008 mov rpc, r13 zsim{23}> is CYCLE=000012 PC=0x200c 0x2009 movl r5, 0x10 zsim{24}> CYCLE=000013 PC=0x200c 0x200a movh r5, 0x20
8-18
ZSIM Simulator
zsim{25}> CYCLE=000013 PC=0x200c 0x200b nop zsim{26}> CYCLE=000015 PC=0x200d 0x200c call r5 zsim{27}> CYCLE=000020 PC=0x2014 0x2010 mov r13, rpc
8.2.21 load dmem
This command loads internal or external data memory from the specified text file. You must specify internal or external memory, the starting address, and the size of the region to load. You must ensure that the format of the text file is the same as the file produced by the dump command. The first column contains the data that will be loaded, with each data on a single line. Data must be in hex format without the 0x prefix. Comments must be enclosed by `/* */ '. Format load dmem {int|ext} filename addr size Example zsim{32} load dmem int data.dat 0x1000 20 The output format of the file is: %cat data.dat 2ce5 /* 0x0000 3c3f /* 0x0001 2000 /* 0x0002 3006 /* 0x0003 a00f /* 0x0004 80c0 /* 0x0005 ... */ */ */ */ */ */
8.2.22 load exe
This command loads a valid ZSP executable into instruction memory. This command performs the same function as specifying the executable filename when ZSIM is invoked. Format
ZSIM Commands
8-19
load exe filename Example zsim{32} load exe test.exe or zisim{32} load test.exe
8.2.23 load imem
This command loads internal or external instruction memory from specified text file. You must specify internal or external memory, the starting address, and the size of the region to load. You must ensure that the format of the text file is the same as the file produced by the dump command. The first column contains the data that will be loaded, with each data on a single line. Data must be in hex format without the 0x prefix. Comments must be enclosed by `/* */ '. Format load imem {int|ext} filename addr size Example % cat inst.txt 2ce5 /* 0x0000 3c3f /* 0x0001 2000 /* 0x0002 3006 /* 0x0003 a00f /* 0x0004 80c0 /* 0x0005 bc4c /* 0x0006 6f4c /* 0x0007 */ */ */ */ */ */ */ */
zsim{32} load imem int imem.txt 0x1000 8
8.2.24 reset
This command resets the state of the simulator. The default is a soft reset, which initializes all aspects of the simulator except the instruction memory. A hard reset performs full initialization. Format
8-20
ZSIM Simulator
reset [soft|hard] Examples zsim{32} reset zsim{32} reset hard Important: The reset command does not reload the program into memory. In order to restart the program, perform one of the following sequence of commands:
zsim{32} reset zsim{32} set reg pc or zsim{32} reset hard; load Note: zsimg2 doesn't support soft reset feature any more.
8.2.25 run
This command advances the simulator for the specified number of cycles. If no cycle count is specified, the default cycle count defined for the run attribute is used (refer to Section 8.2.27, "set attr," page 8-22). Simulation halts if cycle count is reached, the maximum cycle count is reached, or a system halt occurs. Format run [number_of_cycles] Examples zsim{32} run zsim{32} run 100
8.2.26 script
This command loads and processes script file. The script file may contain any valid ZSIM commands. Comments are allowed in the script file, preceded by the hash (#) character. ZSIM ignores all commands between the # character and the end of line. Empty lines are also ignored. Format
ZSIM Commands
8-21
script filename Example zsim{32} script standard.scr Example Script File # This example script demonstrates how to turn on # instruction and pipeline tracing using a command. load test.exe enable trace write enable trace pipe run exit
8.2.27 set attr
The set attr command allows you to set three internal ZSIM attributes. These configurable attributes are shown in Table 8.7. Table 8.7
Attribute history radix run
Configurable ZSIM Attributes
Value any integer {dec | hex} any integer Description Number of commands to maintain in history buffer. Radix (decimal or hexadecimal) used to generate output. Default cycle count for the run command (when issuing the run command with no argument). If undefined by the set attr command, the default run value is 100000 cycles.
Format set attr attribute value Examples zsim{32} set attr run 1000 zsim{32} set attr radix hex
8-22
ZSIM Simulator
8.2.28 set break
This command creates and enables a new breakpoint at specified address. Breakpoints can be set for the program counter. Execution halts at the cycle when the instruction at the specified address is in the set of instructions which are about to be executed in the pipeline's E stage. When a new breakpoint is created, it is tagged with a breakpoint number which is used by other breakpoint commands. Use the show break command to display a list of current breakpoints. Format set break pc addr set break symbol label Example zsim{1} set break pc 0x0010 Breakpoint 1 on PC at address 0x0010 zsim{2} set break symbol main Breakpoint 2 on PC at address 0xf9b9 of main
8.2.29 set delay
This command sets the delay wait state of external data memory or instruction memory. The default delay value is 1 for both external data and instruction memory. The wait state is the number of cycles between requesting data and having it returned. For example, wait state equals 1 means that data is returned 1 cycle after it is requested. Format set delay {edata | einst} num Example zsim{1} set delay edata 10 zsim{2} set delay einst 20 Note: This command is specific to zsim400
ZSIM Commands
8-23
8.2.30 set latency
This command sets the delay wait state of internal/external data memory or instruction memory. The default delay value is 2 for both internal data and instruction memory. The default delay value is 5 for both external data and instruction memory. The wait state is the number of cycles between requesting data and having it returned. For example, wait state equals 2 means that data is returned 2cycles after it is requested. Format set latency {imem | dmem} {int | ext} num Example zsim{1} set latency dmem int 10 zsim{2} set latency dmem ext 20 Note: This command is specific to zsimg2
8.2.31 set reg
This command assigns a new value to the specified register. Format set reg register value Example zsim{32} set reg r0 0x1234
8.2.32 set size
8.2.32.1 zsim400 This command sets the size of internal data memory or instruction memory. The default size of internal data or instruction memory is 63488 words (62K words), which is also the maximum size that can be set.
8-24
ZSIM Simulator
Important:
This command does not apply to external memory. (The simulator has 1M words for each external instruction and external data memory.)
Format set size {dmem|imem} size Examples zsim{1} set size dmem 0x4000 zsim{2} set size imem 0x3000
8.2.32.2 zsimg2 This command sets the size of internal/external instruction or data memory from a begin value to an end value. The boundary is inclusive. The default size for each of the 4 memory types is the maximum value from 0 to 0x00ffffff words (16M words). A word is a 16-bit value for the ZSPG2 architecture. Format set size {dmem|imem} {int|ext} beg_value end_value Examples zsim{1} zsim{2} zsim{3} zsim{4} set set set set size size size size dmem imem dmem imem int int ext ext 0 0 0 0 0xffff 0xffff 0x00fffff 0x00fffff
8.2.33 show attr
This command displays the value of the specified attribute. See set attr for a list of defined attributes. Note that the version attribute can only be used with the show attr command; it cannot be used with the set attr command. Format show attr {history|radix|run|version} Example
ZSIM Commands
8-25
zsim{32} show attr run
8.2.34 show bits
This command displays the bit field values for the specified register. When specifying control registers, do not include the percent (%) sign. Format show bits register Example zsim{32} show bits hwflag hwflag = 0x0000 er: 0 ex: 0 ir: 0 z: 0 gt: 0 ge: 0 c: 0 gsv: 0 sv: 0 gv: 0 v: 0
8.2.35 show break
This command displays the list of currently defined breakpoints. Format show break Example zsim{32} show break
8.2.36 show dcache
This command displays the current contents of the data cache. Format show dcache Example
8-26
ZSIM Simulator
For zsim400 simulator R13 R13 R13 R14 R14 R14 R15 R15 R15 UL UL UL UL UL UL UL UL zsim{1}> show dcache - D$[ 0]: ------ I ------ D$[ 1]: ------ I ------ D$[ 2]: ------ I ------ D$[ 3]: ------ I ------ D$[ 4]: ------ I ------ D$[ 5]: ------ I ------ D$[ 6]: ------ I ------ D$[ 7]: ------ I ------ D$[ 8]: ------ I ------ D$[ 9]: ------ I ------ D$[10]: ------ I ------ D$[11]: ------ I ------ D$[12]: ------ I ------ D$[13]: ------ I ------ D$[14]: ------ I ------ D$[15]: ------ I ------ D$[16]: ------ I ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The first 9 lines are dedicated for linked load of r13, 14, and 15 register respectively. The next 8 lines are used for any unlinked load. The first "------" column is showing the address of the line. The next column indicates the line invalid `I' or valid. The next 4 columns are showing the data contains in that line. For zsimg2 > zsim{1}> show dcache D$[ 0] 0x000001 ----------- ------ lru[0] D$[ 1] 0x000001 ----------- -----D$[ 2] 0x000001 ----------- -----D$[ 3] 0x000001 ----------- -----D$[ 4] 0x000001 ----------- -----D$[ 5] 0x000001 ----------- -----D$[ 6] 0x000001 ----------- -----D$[ 7] 0x000001 ----------- -----D$[ 8] 0x000001 ----------- ------
------ ------ ------ ------ ----------- ------ ------ ------ ----------- ------ ------ ------ ----------- ------ ------ ------ ----------- ------ ------ ------ ----------- ------ ------ ------ ----------- ------ ------ ------ ----------- ------ ------ ------ ----------- ------ ------ ------ ------
ZSIM Commands
8-27
D$[ 9] 0x000001 ------ ------ ------ ------ ------ ----------- -----D$[10] 0x000001 ------ ------ ------ ------ ------ ----------- -----D$[11] 0x000001 ------ ------ ------ ------ ------ ----------- -----The first column shows the address and the next 8 columns contain data.
8.2.37 show dmem
This command displays a range of internal or external data memory. The user specifies internal or external memory, the starting address, and the size of the region to display. The default settings for the show dmem command are shown in Table 8.9. Table 8.8
Argument {int | ext} addr size
Default Arguments for show dmem
Value int 0x0 16
Format show dmem {int|ext} addr size Example zsim{32} show dmem int 0xf000 0x10 For zsimg2, user can use a symbol instead of an absolute address. zsim{1} show dmem int array1 20
8.2.38 show icache
This command displays the current contents of the instruction cache. Format show icache
8-28
ZSIM Simulator
Example zsim{32} show icache
8.2.39 show imem
This command displays a range of internal or external instruction memory. The size and addr fields may be omitted, in which case defaults are used. The default settings for the show imem command are shown in Table 8.9. Table 8.9
Argument {int | ext} addr size
Default Arguments for show imem
Value int 0x0 16
Format show imem {int|ext} [addr] [size] Example zsim{1} show imem int 0xf000 0x10 For zsimg2, user can use symbol instead of absolute address value. zsim{1} show imem int foo_function 20
8.2.40 show pipe
This command shows the contents of all stages of the pipeline. Format show pipe Example zsim{32} show pipe
ZSIM Commands
8-29
8.2.41 show profile
This command shows the current status (enabled/disabled) for each profile type. Format show profile Example zsim{32} show profile ***(info) Supported profile information: - Instruction Unit: OFF - Data Unit: OFF - Pipeline Unit: OFF
8.2.42 show reg
This command displays the values of a category of registers or the value of the specified register. You can list more than one category and/or register. The register categories are:
* *
gpr All general purpose registers, r0-r15. cfg All control registers (such as %smode and %hwflag). Do not include the percent (%) sign in the control register name.
*
addr All address and index registers for the ZSPG2 architecture. Thus, it is specific for zsimg2.
Format show reg [category|register] ... Examples zsim{32} show reg zsim{32} show reg r0 zsim{32} show reg hwflag smode (Do not include the percent (%) sign.)
8-30
ZSIM Simulator
8.2.43 show rule
This command displays the affected grouping rule for the current cycle. Format show rule Examples zsim{32} show pipe CYCLE: 8 ------------------------------------------ F(4:2) (13)000d:5448:0:mac2.a r4.e, r8.e (12)000c:788f:0:lddu r8.e, r15, 2 (11)000b:784e:1:lddu r4.e, r14, 2 (10)000a:9a00:1:xor.e r0.e, r0.e ------------------------------------------ G(4:2) (9)0009:2d18:0:movl r13, 0x18 (8)0008:3f00:0:movh r15, 0x0 (7)0007:3d01:1:movh r13, 0x1 (6)0006:3e00:1:movh r14, 0x0 ------------------------------------------ R(0:0) ------------------------------------------ E(1:1) (5)0005:ad02:1:bits fmode, 2 ------------------------------------------ W(1:1) (4)0004:d700:1:movl guard, 0x0 zsim{33} show rule Active grouping rule in current cycle: 23. Only two instructions requiring an alu or one instruction that requires both the alus can be grouped.
8.2.44 show size
Show size of internal data or instruction memory. The output is not affected by the radix attribute. Format show size {dmem|imem}{int|ext} Examples zsim{32} The size zsim{32} The size show size dmem int of internal data memory is 0xf800 words. show size imem int of internal instruction memory is 0xf800 words.
ZSIM Commands
8-31
8.2.45 show stats
Display all the run-time statistics generated by ZSIM. If no argument is specified, ZISIM displays overall statistical information. If the opcode argument is specified, ZISIM displays instruction opcode statistics. Format show stats Example zsim{32} show stats zsim{32} show stats opcode
8.2.46 show trace
Show currently enabled/disabled trace information. Traces currently set to ON are enabled during simulation. Format show trace Example zsim{32} show trace ***(info) Supported trace information: - Instruction trace: OFF - Pipeline trace: OFF - Register trace: OFF - Memory trace: OFF zsim{33} enable trace pipe ***(info) Pipeline trace is ON. zsim{34} show trace ***(info) Supported trace information: - Instruction trace: OFF - Pipeline trace: ON - Register trace: OFF - Memory trace: OFF
8.2.47 step
Single-step the simulator. Issuing the step command is equivalent to issuing the command run 1.
8-32
ZSIM Simulator
Format step Example zsim{32} step
8.2.48 unalias
Deletes an alias. Format unalias [alias] Example zsim{32} unalias adv
8.3 I/O Port Usage
ZSIM400 models serial I/O as a memory-mapped device. Programs perform terminal I/O by reading from and writing to the appropriate address locations. The simulator defines two serial ports and one host processor interface (HPI) port. Each port has a transmit buffer and a receive buffer. Table 8.10 shows the memory addresses and corresponding files for the I/O ports for the LSI402ZX, LSI403Z, and ZSP400-core based devices. Table 8.10 I/O Device Memory Map and Associated Files
Read I/O Port Serial Port 0 Serial Port 1 Host Interface Port Address 0xF901 0xFA01 0xFB01 File sp0in sp1in hpiin Address 0xF900 0xFA00 0xFB00 Write File sp0out sp1out hpiout
I/O Port Usage
8-33
The format of input and output files are the same. Data must be in decimal digits, with each data on a single line. If the input file is not present in the current running directory at the time of the request, the simulator will print an error message to standard output and exit. ZSIM400 also supports user-specified I/O ports. You can create a library containing peripheral devices and then use it in place of the default library in the directory $SDSP_HOME/sdspI/bin, which is created when the ZSP SDK tools are installed. The peripheral library is called libzperiph.dll on Windows and libzperiph.so on Solaris platforms. For information on writing the peripheral library, refer to the ZSIM Peripheral API Reference Guide, document DB06-000299-00.
8.4 Example Session Using ZSIM
This section contains an example simulation session using ZSIM in interactive mode.
zsim{1}> load exe test.exe ***(info) Starting address: 0x2000 .text : Loading to INT-INST memory ... 0x2000 -> 0x2950 (0x0951) .data : Loading to INT-DATA memory ... 0x0001 -> 0x005f (0x005f) Loading "test.exe" successfully.
The contents of the instruction memory can be checked to confirm proper loading of the test:
zsim{2}> 0x2000 0x2001 0x2002 0x2003 zsim{3}> show imem int 0x2000 4 0x2cfb movl r12, 0xfb 0x3cf7 movh r12, 0xf7 0xa6d0 mov r13, 0x0 0x2460 movl r4, 0x60 _
Before execution cycles begin, you can check to make sure that the pipeline and caches are empty:
zsim{3}> show pipe -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------F(0:0) G(0:0) R(0:0) E(0:0) W(0:0)
As shown above, the five stages of the execution pipeline are identified with a single letter - F (Fetch/decode), G (Group), R (Read), E (Execute),
8-34
ZSIM Simulator
and W (Write Back) - followed by two integers representing the number of instructions currently in that stage and the number of instructions that will advance to the next stage in the following cycle.
zsim{4}> show I$[0]: -----I$[1]: -----I$[2]: -----I$[3]: -----I$[4]: -----I$[5]: -----I$[6]: -----I$[7]: -----icache I -----I -----I -----I -----I -----I -----I -----I -----I I I I I I I I ----------------------------------------I I I I I I I I ----------------------------------------I I I I I I I I -----------------------------------------
In the above example, the 8 lines of the instruction cache are shown to be empty . The first column contains the address (4 word boundary) and the remaining 4 columns contain the corresponding instruction opcodes. An `I' to the left of a cell indicates an invalid instruction.
zsim{5}> show R13 - D$[ 0]: R13 - D$[ 1]: R13 - D$[ 2]: R14 - D$[ 3]: R14 - D$[ 4]: R14 - D$[ 5]: R15 - D$[ 6]: R15 - D$[ 7]: R15 - D$[ 8]: UL - D$[ 9]: UL - D$[10]: UL - D$[11]: UL - D$[12]: UL - D$[13]: UL - D$[14]: UL - D$[15]: UL - D$[16]: dcache -------------------------------------------------------------------------------------I I I I I I I I I I I I I I I I I -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The 17 lines of the data cache are shown to be empty in the above example. The first column contains the address (4-word boundary) and the remaining 4 columns contain data values. An `I' to the left of a data line indicates that the corresponding data line is invalid. Continuing with the example, as execution proceeds, the pipeline and instruction cache reflect changes expected by instruction flow:
zsim{6}> run 4 ; show pipe CYCLE=000004 PC=0x2000 CYCLE: 4
Example Session Using ZSIM
8-35
------------------------------------------ F(4:1) (7)2007:6054:0:st r5, r4, 0 (6)2006:a051:0:add r5, 0x1 (5)2005:bc54:0:mov r5, r4 (4)2004:3400:1:movh r4, 0x0 ------------------------------------------ G(4:1) (3)2003:2460:0:movl r4, 0x60 (2)2002:a6d0:0:mov r13, 0x0 (1)2001:3cf7:0:movh r12, 0xf7 (0)2000:2cfb:1:movl r12, 0xfb ------------------------------------------ R(0:0) ------------------------------------------ E(0:0) ------------------------------------------ W(0:0) zsim{7}> show icache I$[0]: 0x2000 V 0x2cfb V 0x3cf7 V 0xa6d0 V 0x2460 I$[1]: 0x2004 V 0x3400 V 0xbc54 V 0xa051 V 0x6054 I$[2]: ------ I ------ I ------ I ------ I -----I$[3]: ------ I ------ I ------ I ------ I -----I$[4]: ------ I ------ I ------ I ------ I -----I$[5]: ------ I ------ I ------ I ------ I -----I$[6]: ------ I ------ I ------ I ------ I -----I$[7]: ------ I ------ I ------ I ------ I -----zsim{8}> _
The simulator output below demonstrates use of the PC breakpoint. A breakpoint is set for address 0x10 and the simulator is advanced. Execution halts when the instruction associated with the breakpoint address reaches the Group stage. The state of the pipeline and operand registers are shown after the breakpoint halt occurs.
zsim{8}> set break sym main Breakpoint 1 on PC at address 0x2010 of main zsim{9}> enable trace write ***(info) Instruction trace is ON. zsim{10}> run <6> (0) 0x2000 2cfb movl r12, 0xfb ! r12 = 0x00fb <7> (1) 0x2001 3cf7 movh r12, 0xf7 ! r12 = 0xf7fb <7> (2) 0x2002 a6d0 mov r13, 0x0 ! r13 = 0x0000 <8> (3) 0x2003 2460 movl r4, 0x60 ! r4 = 0x0060 <9> (4) 0x2004 3400 movh r4, 0x0 ! r4 = 0x0060 <10> (5) 0x2005 bc54 mov r5, r4 ! r5 = 0x0060 <11> (6) 0x2006 a051 add r5, 0x1 ! hwflag = 0x0030 <11> (6) 0x2006 a051 add r5, 0x1 ! r5 = 0x0061 <11> (7) 0x2007 6054 st r5, r4, 0 ! INT-DATA[0x0060] = 0x0061 <12> (9) 0x2009 2510 movl r5, 0x10 ! r5 = 0x0010 <13> (8) 0x2008 bb1d mov rpc, r13 ! rpc = 0x0000 <13> (10) 0x200a 3520 movh r5, 0x20 ! r5 = 0x2010 <14> (12) 0x200c a750 call r5 ! rpc = 0x200d (PC BREAKPOINT #1)....................... CYCLE=000020 PC=0x2014
Trace information is displayed in six fields:
8-36
ZSIM Simulator
* * * * * *
The first field is the cycle count number (enclosed by `< >'). The second field is the instruction sequence number (in parenthesis). The third field is the program counter (PC) of the executed instruction. The fourth field is the instruction opcode. The fifth field is the disassembled instruction, including operands. The sixth field describes the result of the executed instruction.
zsim{11}> run 7; show pipe <20> (13) 0x2010 2501 movl r5, 0x1 ! r5 <20> (14) 0x2011 b91d mov r13, rpc ! r13 <21> (15) 0x2012 3500 movh r5, 0x0 ! r5 <21> (16) 0x2013 6fdc stu r13, r12, -1 ! INT-DATA[0xf7fb] <21> (16) 0x2013 6fdc stu r13, r12, -1 ! r12 <22> (17) 0x2014 a0cf add r12, 0xffff ! hwflag <22> (17) 0x2014 a0cf add r12, 0xffff ! r12 <22> (19) 0x2016 1060 call 0x20d6 ! rpc <23> (18) 0x2015 615c st r5, r12, 1 ! INT-DATA[0xf7fa] <25> (20) 0x20d6 a641 mov r4, 0x1 ! r4 <26> (21) 0x20d7 b91d mov r13, rpc ! r13 <26> (22) 0x20d8 6fdc stu r13, r12, -1 ! INT-DATA[0xf7f9] <26> (22) 0x20d8 6fdc stu r13, r12, -1 ! r12 <27> (23) 0x20d9 bc6c mov r6, r12 ! r6 CYCLE=000027 PC=0x20dc CYCLE: 27 ------------------------------------------ F(4:3) (33)20ea:bc34:0:mov r3, r4 (32)20e9:6f7c:1:stu r7, r12, -1 (31)20e8:b910:1:mov r0, rpc (30)20e7:6b2c:1:stdu r2.e, r12, -2 ------------------------------------------ G(4:3) (29)20e6:3d00:0:movh r13, 0x0 (28)20e5:6b0c:1:stdu r0.e, r12, -2 (27)20e4:2d68:1:movl r13, 0x68 (26)20dc:1004:1:call 0x20e4 ------------------------------------------ R(1:1) (25)20db:a063:1:add r6, 0x3 ------------------------------------------ E(2:2) (24)20da:725c:1:ld r5, r12, 2 (23)20d9:bc6c:1:mov r6, r12 ------------------------------------------ W(2:2) (22)20d8:6fdc:1:stu r13, r12, -1 (21)20d7:b91d:1:mov r13, rpc zsim{12}> show reg gpr r0 = 0x0000 r1 = 0x0000 r2 = 0x0000 r3 = 0x0000 r4 = 0x0001 r5 = 0x0001
= = = = = = = = = = = = = =
0x2001 0x200d 0x0001 0x200d 0xf7fa 0x0040 0xf7f9 0x2017 0x0001 0x0001 0x2017 0x2017 0xf7f8 0xf7f8
Example Session Using ZSIM
8-37
r6 r8 r10 r12 r14 zsim{14}>
= = = = =
0xf7f8 0x0000 0x0000 0xf7f8 0x0000
r7 r9 r11 r13 r15
= = = = =
0x0000 0x0000 0x0000 0x2017 0x0000
Execution halts when a breakpoint is reached, the maximum cycle count is reached, or a system halt occurs. A system halt refers to the halt mode as defined by the power level (lvl) field in the DSP's %smode control register. A simulation session is terminated with the exit command.
zsim{12}> exit ***(info) Exiting ZSIM. %_
8-38
ZSIM Simulator
Chapter 9 Debugger
This chapter describes the SDK source and assembly-level Debugger for the ZSP400 and ZSPG2 architectures. The SDK Debugger, SDBUG, is based on the GNU Debugger (GDB) from the Free Software Foundation. GDB is described in Debugging with GDB: The GNU Source Level Debugger, by Richard Stallman, et. al., Free Software Foundation, January 1994. The description of SDBUG in this chapter, for the most part, includes only the differences from GDB. For Windows 95/98/NT platforms, the debugger can be accessed using the ZSP Integrated Development Environment, as described in Chapter 10, "ZSP Integrated Development Environment (ZSP IDE)." This chapter describes the debugger's standard GNU command-line interface, available for all platforms.
9.1 Using SDBUG
SDBUG is invoked from the command line as follows: [options] [executable_file]
ZSP SDK Software Development Kit
9-1
where debugger name is the name of the desired debugger as listed in Table 9.1. Table 9.1 Debugger Names
Debugger Name Use when debugging... sdbug400 zdxbug code written for devices based on the ZSP400 architecture. code originally written for devices based on the ZSP400 architecture, but cross-compiled for the ZSPG2 architecture. code designed for devices based on the ZSPG2 architecture.
zdbug
The above command both invokes and initializes the debugger. SDBUG-only command-line options are listed in Table 9.2. All other SDBUG options are described in Stallman, et. al. Table 9.2
Option -mempcr=ADDR -no_mempcr -jtag_type=TYPE
SDBUG-Only Options
Description Availability
Sets the address of the mempcr register. sdbug400 Specifies that the hardware target has no MEMPCR register Gives priority to the detection of the JTAG interface specified. TYPE can be either pci (Corelis PCI JTAG), pcmcia (Corelis PCMCIA JTAG), or raven (Macraigor Raven) By default, SDBUG first attempts to use the PCMCIA JTAG card, then the PCI JTAG card, then the Macraigor Raven interface.. sdbug400 sdbug400
-jtag_mapfile=FILE Makes the debugger look for the map file FILE, rather than the default called "mapfile" in the current directory and SDSP_HOME/sdspI/misc.
sdbug400
Use the following command to load the symbol table from the executable file: (sdbug) file a.out
9-2
Debugger
Next select SDBUG's target execution environment (as described in the following section). For example, to target the cycle-accurate simulator: (sdbug) target zsim Use the following command to load the text and data sections of the executable file: (sdbug) load a.out Now you are ready to debug your program using the standard GDB commands.
9.2 SDBUG Execution Environments
The debugger supports four execution environments:
* * * *
Functional-accurate software simulation on the host (using ZISIM) Cycle-accurate software simulation on the host (using ZSIM) Target hardware, connected through the serial port Target hardware, connected through a JTAG controller (Windows 95/98/NT platforms only)
These environments are described in the following subsections.
9.2.1 Functional-Accurate Simulator Connection
The ZISIM target simulator is invoked by the following command: (sdbug) target sim [option...] where option is any of the simulator options described in Table 7.1 on page 7-1. With this connection, program execution is performed by the functional-accurate simulator, ZISIM, under the control of the debugger. The debugger examines the simulator state to process queries from the user. SDBUG uses the functional-accurate simulator commands to select information that is requested from the executing program by the ZISIM
SDBUG Execution Environments
9-3
simulator. These commands are listed in Table 9.3 and described in detail in Section 7.2, "ZISIM Commands," page 7-4. The format for simulator commands using ZISIM is: (sdbug) sim simulator-command Table 9.3
Command clear-stats close filename help max_number_of_files number
SDBUG Target ZISIM Simulator Commands
Description Resets the statistics. Closes file filename.1 Displays the list of simulator commands that can be invoked. Sets the maximum number of files that can be opened at the same time to number.1
memory_download filename addr size Writes size of items to memory addr from file filename.1 memory_upload filename addr size print-stats reg-off reg-on trace-off trace-on clear-opcode print-opcode Reads size of items from memory addr to file filename.1 Prints statistics such as instruction mix, load, store, discontinue, and mispredicts to stdout. Sets the simulator register tracing off. Sets the simulator register tracing on. Sets the simulator trace off. Sets the simulator trace on. Resets statistics of opcode usage. Prints statistics of opcode usage.
1. This command may also be invoked without specifying the target name. See Section 9.3.1, "Generic Target-Specific Commands" on page 9-11 for details.
9.2.2 Cycle-Accurate Simulator Connection
The ZSIM target simulator is invoked by the following command: (sdbug) target zsim
9-4
Debugger
With this connection, the cycle-accurate simulator (ZSIM) executes your program under the control of the debugger. The debugger examines the simulator state to process queries from the user. The cycle-accurate simulator commands are used to select information that is requested from the executing program by the ZSIM simulator. These commands are listed in Table 9.4 and described in detail in Section 8.2, "ZSIM Commands," page 8-5. The format for ZSIM commands is: (sdbug) zsim simulator-command Table 9.4
Command clear-stats clear-opcode close filename help max_number_of_files number memory_download filename addr size memory_upload filename addr size pfdu-off pfdu-on pfiu-off pfiu-on pfpipe-off pfpipe-on pipe-off (Sheet 1 of 2)
SDBUG Target ZSIM Commands
Description Resets the general statistics. Resets the opcode usage statistics. Closes file filename.1 Displays the list of simulator commands that can be invoked. Sets the maximum number of files that can be opened at the same time to number.1 Writes size of items to memory addr from file filename.1 Reads size of items from memory addr to file filename.1 Turns off data unit profile information. Turns on data unit profile information. Turns off instruction unit profile information. Turns on instruction unit profile information. Turns off pipeline unit profile information. Turns on pipeline unit profile information. Sets the simulator pipeline off.
SDBUG Execution Environments
9-5
Table 9.4
Command pipe-on print-dcache print-icache print-opcode print-pipe
SDBUG Target ZSIM Commands (Cont.)
Description Sets the simulator pipeline on. Prints contents of data cache to stdout. Prints contents of instruction cache to stdout. Prints instruction opcode history to stdout. Prints contents of the pipeline to stdout. Prints collected profile information to stdout. Prints grouping rule to stdout2. When cycle count is on, prints statistics to stdout. Prints incremental statistics information to stdout. Collects profile information for functionName from start to end addresses. Follow by profile-on command to turn on the profile collector. Collects profile information for all functions in the program. Follow by the profile-on command to turn on the profile collector. Turns off profile collector. Turns on profile collector Sets the simulator register tracing off. Sets the simulator register tracing on. Sets the simulator trace off. Sets the simulator trace on.
print-profile print-rule [# | all] print-stats print-stats-inc pf functionName start end
profile-func
profile-off profile-on reg-off reg-on trace-off trace-on (Sheet 2 of 2)
1. This command may also be invoked without the target name. See Section 9.3.1, "Generic TargetSpecific Commands" on page 9-11 for details. 2. The optional arguments only work in sdbug400. zdbug and zdxbug only supports the display of the grouping rules that are currently active.
9.2.2.1 User-Specified Profiling When used with the cycle-accurate simulator, the debugger supports profiling of selected areas of your project code. To use this feature, you
9-6
Debugger
must define the regions to be profiled using the following pair of assembler directives in your source code: asm("\n__FUNC_START_region_name:"); asm("\n__FUNC_EXIT_region_name:"); The profiling can then be enabled using the following commands: (sdbug) profile-func (sdbug) profile-on Execute the program by typing: (sdbug) run Display the profiling statistics using: (sdbug) print_profile With respect to profiling, the profile-func command will treat region_name just like a function. Note that for function profiling to operate correctly, execution that passes through the start label must also pass through the exit label.
9.2.3 UART Connection
The UART connection is invoked by the following commands: (sdbug) set remotebaud [baud_rate] (sdbug) target sdsp-remote serial_port The required baud rate can be specified when setting remotebaud. The default baud rate setting is 38400. To use this connection, your target evaluation board must be able to support UART-based debugging with appropriate hardware and firmware. In addition, your target must be booted from flash memory that contains the UART debug code. For instructions on programming the flash memory, refer to the application note, Programming the Flash. To ensure that your EB402 Evaluation Board is booted from (external) flash
SDBUG Execution Environments
9-7
memory, set the IBOOT pin LOW. Refer also to the EB402 Evaluation Board User's Guide. Use the SDBUG commands in Table 9.5 to communicate with the target board though the serial port connection. The format for serial port commands is: (sdbug) sdsp-remote sdsp-remote-command Table 9.5
Command close file filename help max_number_of_files number
SDBUG UART Connection Commands
Description Close file filename.1 List UART connection commands. Specify the maximum number of files that can be opened at the same time.1
memory_download filename addr size Write size of items to memory addr from file filename. addr can be a label.1 memory_upload filename addr size Read size of items from memory addr to file filename. addr can be a label.1
1. This command may also be invoked without the target name. See Section 9.3.1, "Generic TargetSpecific Commands" on page 9-11 for details.
9.2.4 JTAG Controller Connection
To use the JTAG connection, you must install a Corelis PCI or PCMCIA Type II Boundary Scan Controller card on your Windows machine and install a cable connecting it to your evaluation board. Note: The JTAG target is available only for Windows 95/98/NT platforms.
The JTAG target is invoked by the following commands: (sdbug) jtag set_clk 2 0 0 (sdbug) target jtag The first command is required to set the parameters for the JTAG clock (TCK) on the Corelis Boundary Scan Controller card, where the first parameter (2) specifies the base clock oscillator to be used (50 MHz), the
9-8
Debugger
second parameter (0) disables the clock prescaler, and the third parameter (0) is used as the clock divisor (divide by 2). (These are the default settings for boards running at 100 MHz and above.) The second command establishes the connection. Refer to the Corelis Software Development Kit User's Manual for information on supported JTAG clock speeds. The JTAG commands described in Table 9.6 are used to select information that is requested from the target using the JTAG connection. The format for JTAG commands is: (sdbug) jtag jtag-command Table 9.6
Command close filename help set_clk val1 val2 val3
SDBUG JTAG Commands
Description Close file filename.1 List JTAG commands. Sets the JTAG clock according to the JTAG interface in question. With the Corelis JTAG interfaces, the values are base clock occillator, prescaler enable, and clock divisor, respectively. For Macraigor Raven, it would be the speed value followed by two zeros. Generally speaking, fthe JTAG clock speed should be approximately 1/10th to 1/20th of the ZSP clock speed.
raven_lpt port max_number_of_files number
Tells the debugger to use LPT 1, 2, or 3 as the Raven LPT port. Specify the maximum number of files that can be opened at the same time.1
memory_download filename addr size Write size of items to memory addr from file filename. addr can be a label.1 memory_upload filename addr size Read size of items from memory addr to file filename. addr can be a label.1
1. This command may also be invoked without the target name. See Section 9.3.1, "Generic TargetSpecific Commands" on page 9-11 for details.
SDBUG Execution Environments
9-9
9.2.4.1 Hardware-Assisted Debugging The JTAG target environment supports hardware-assisted debugging. The format for a hardware-assisted debugging command is: (sdbug) hw hardware_assisted_debugging_command Important: All breakpoints must be disabled before using hardware-assisted debugging. Only one breakpoint may be set, and when it is set, any previously-set breakpoint is deactivated. You cannot perform I/O during hardwareassisted debugging. Hardware-assisted debugging will function correctly only with the correct map file for the specific part being debugged. The SDK comes with the map file for LSI402ZX rev. 1 (mapfile), LSI402ZX rev. 2 (mapfile_rev2), and LSI403LP (mapfile_403lp); if your application uses a different processor, please contact the vendor for the correct map file. The default map file loaded is mapfile. To change the map file used, either copy the new map file to the directory the debugger is inovked in as "mapfile," or copy to the current directory or $SDSP_HOME/sdspI/misc and use the --jtag_mapfile command line option to specify the map file to use.
Important:
The commands available for hardware-assisted debugging are shown in Table 9.7. Table 9.7
Command enable_ice resume step n insn_addr_brk addr st_addr_brk addr st_data_brk data
Hardware-Assisted Debugging Commands
Description Enable hardware-assisted debugging. Resume execution. Step n cycles. Set a breakpoint when executing an instruction at addr. Set a breakpoint when storing to addr. Set a breakpoint when storing the value data.
9-10
Debugger
Table 9.7
Command
Hardware-Assisted Debugging Commands (Cont.)
Description Set a breakpoint when storing data to addr. Set a breakpoint when storing to addr or storing the value data. Disable hardware breakpoint. Returns to software debug mode. Must have executed in hardware debug mode for at least one cycle in order for this to work.
st_addr_and_data_brk addr data st_addr_or_data_brk addr data disable_brk return_to_sw_dbg
9.3 Debugger Commands - Special Cases
Some SDBUG commands have special cases, which are described in the following subsections. For more information on the usage of any command, issue the help command at the (sdbug) prompt.
9.3.1 Generic Target-Specific Commands
To make test scripts that need to run under multiple targets more generic, the hardware and software target-specific commands memory_upload, memory_download, close, and max_number_of_files may now be used without their target prefixes after the target has been specified. For example, the command: (sdbug) jtag max_number_of_files 1 may be replaced by (sdbug) max_number_of_files 1 within a script after you have issued the target command.
9.3.2 Backtrace Command
To use the backtrace command, you must adhere to the calling conventions described in Section 3.2, "Compiler Conventions." To use this command to display the call stack, set breakpoints on the function
Debugger Commands - Special Cases
9-11
name. This command may display incorrect results when the debugger is halted inside a function prologue or epilogue.
9.3.3 Info Registers Command
9.3.3.1 sdbug400, zdxbug To use this command, the %rpc register must be stored on the stack, even for leaf functions. Otherwise, the compiler returns incorrect values for the %pc and %rpc registers when traversing the stack. Refer to Section 3.2, "Compiler Conventions." 9.3.3.2 zdbug The code still needs to following the compiler convention, though the convention has now been changed. Refer to Section 3.2, "Compiler Conventions." for details.
9.3.4 Breakpoint Command
SDBUG reserves the use of pc value zero. If two breakpoints are inadvertently set at pc value zero, the debugger will loop while trying to execute the instruction. If a breakpoint has to be set at pc value zero, set only one breakpoint at that address.
9.3.5 Print Command
The print command is typically used to display the values of variables and arrays. It may also be used to display the values in any memory location.
9.3.6 Set Command
The set command is used to change the state of the processor or the debugger. It can be used to change any register value, the value of any word in any memory, or the value of any variable. Keep in mind that with the cycle-accurate simulator (ZSIM), the set command may not operate correctly if it is used to change the contents of a register that will be used by an instruction currently in the pipeline-- if the instruction is in a pipeline stage older than Group (G), the instruction may read the old value. Also, using the ZSIM set to modify a
9-12
Debugger
memory location that has already been loaded into the data cache will modify both the data cache and the memory. (With the UART and JTAG targets, modifying memory will not affect the data cache.)
9.3.7 Cycle-Step Command
The cycle-step command is only available for use with the cycleaccurate simulator (ZSIM). This command causes the simulator to advance the pipeline cycle-by-cycle. Format: cycle-step # Example: (sdbug) cycle-step 10 The simulator will be advanced by 10 clock cycles.
9.3.8 Accessing Memory with the Debugger
9.3.8.1 sdbug400, zdxbug Debugger commands use memory addresses that are seven hexadecimal digits in length. The address format is shown in Figure 9.1. The seventh (leftmost and most-significant) digit is the page number (0x0-0xF) from the mempcr register, the sixth digit selects between internal (0) or external (1) memory, the fifth digit selects instruction (0) or data (2) memory, and the first four (rightmost and least-significant) digits are the normal 16-bit address. If any of the three most-significant digits are omitted from an address, they are assumed to be zero.
Debugger Commands - Special Cases
9-13
Figure 9.1
Debugger Memory Addressing (sdbug400, zdxbug) 0x0123456
Page Number from mempcr register Internal (0) or External (1) Memory
Address
Instruction (0) or Data (2) Memory
Note:
All other ZSP SDK tools and linker scripts use four-digit addressing. The debugger is the only tool that uses sevendigit memory addressing.
Some examples of debugger memory addressing are shown below:
0x0001000 0x0022000 0x0103000 0x2124000 0xa105000 Internal instruction at address 0x1000 Internal data at address 0x2000 Page 0, external instruction memory at address 0x3000 Page 2, external data memory at address 0x4000 Page 10, external instruction memory at address 0x5000
9.3.8.2 zdbug Debugger commands use memory addresses that are eight hexidecimal digits in length. The address format is shown in Figure 9.2. The eighth (leftmost and most-significant) digit's fourth bit (0x80000000) selects between internal (0) or external (1) memory, the eighth digit's third bit (0x40000000) selects instruction (0) or data (1) memory. The other seven digits are used to determine the address. If any of the leftmost digits are ommitted from an address, they are assumed to be zero.
9-14
Debugger
Figure 9.2
Debugger Memory Addressing (zdbug) 0x01234567
Address
Internal (0) or External (8) Memory Instruction (0) or Data (4) Memory
Note:
All other ZSP SDK tools and linker scripts use 24-bit addressing. The debugger is the only tool that uses 30-bit addressing.
Some examples of debugger memory addressing are shown below:
0x00001000 0x40002000 0x80003000 0xC0004000 0x30000000 0xF0000100 Internal instruction at address 0x1000 Internal data at address 0x2000 External instruction memory at address 0x3000 External data memory at address 0x4000 Internal Instruction at address 0x300000000 External data memory at address 0x30000100
9.4 Dynamic Breakpoints
Command-line debugging supports dynamic breakpoints for all target execution environments while in software debug mode. Dynamic breakpoints are set by pressing cntl-C.
9.5 Example Debugging Sessions
This section contains two examples demonstrating the use of SDBUG. The first example uses the functional-accurate simulator, ZISIM. The second example uses the JTAG controller connection for hardwareassisted debugging.
Dynamic Breakpoints
9-15
9.5.1 Example 1
In this sample debugging session, the executable is built from the C and assembly programs shown in Appendix A, "Example Programs" The name of the executable is demo.exe, and the start address is 0x1000. The target is set to the functional-accurate simulator (ZISIM) for the LSI402Z. The complete command name is used the first time the command is invoked (for example, backtrace); subsequent invocations use the abbreviated command name (bt).
(shell) sdbug400 GNU gdb 4.18 Copyright 1998 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "--host=sparc-sun-solaris2.6 --target=sdsp-ZSP-elf"... (sdbug) file demo.exe Reading symbols from demo.exe...done. (sdbug) target sim Connected to the simulator. (sdbug) load demo.exe .text : 0x 0 .. 0x cd ... Loading .data : 0x cd .. 0x cf ... Loading Transfer rate: 3312 bits in <1 sec. (sdbug) breakpoint main Breakpoint 1 at 0x13: file demo.c, line 9. (sdbug) b func_1 Breakpoint 2 at 0x56: file func1.s, line 9. (sdbug) b func_2 Breakpoint 3 at 0x89: file func2.c, line 4. (sdbug) b func_3 Breakpoint 4 at 0x70: file func1.s, line 50. (sdbug) run Starting program: /user/Tools/MyProject02/demo.exe Breakpoint 1, main () at demo.c:9 9 char ch = 'A'; (sdbug) list 4 5 int t=500; 6 7 main() 8 { 9 char ch = 'A'; 10 int i,j = 100,k; 11 12 for (i=0; i< 2; i++) { 13 func_2();
9-16
Debugger
(sdbug) step 10 int i,j = 100,k; (sdbug) print j $1 = 0 (sdbug) p i $2 = 0 (sdbug) continue Continuing. Breakpoint 3, func_2 () at func2.c:4 4 int x=0,n=0; (sdbug) next 5 while(n < 20) (sdbug) n 5 25 t1 = x; (sdbug) backtrace #0 func_2 () at func2.c:25 #1 0x21 in main () at demo.c:13 (sdbug) up #1 0x21 in main () at demo.c:13 13 func_2(); (sdbug) down #0 func_2 () at func2.c:25 25 t1 = x; (sdbug) info reg r2 r3 r12 rpc pc r2 0x0 0 r3 0x0 0 r12 0xf7f3 -2061 rpc 0x21 33 pc 0xc0 192 (sdbug) c Continuing. Breakpoint 2, func_1 () at func1.s:14 14 mov r5, r4 Current language: auto; currently asm (sdbug) l 9 mov r13, %rpc 10 stu r13, r12, -1 11 12 /** END PROLOGUE **/ 13 14 mov r5, r4 15 ld r4, r5 16 mov r6, 500 17 cmp r4, r6 /* *t <= 500; */ 18 bgt L2 (sdbug) s 6 20 mov r6, 100 (sdbug) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x00000013 in main at demo.c:9 breakpoint already hit 1 time
Example Debugging Sessions
9-17
2
breakpoint keep y 0x00000056 func1.s:9 breakpoint already hit 1 time 3 breakpoint keep y 0x00000089 in func_2 at func2.c:4 breakpoint already hit 1 time 4 breakpoint keep y 0x00000070 func1.s:50 (sdbug) delete 4 (sdbug) b demo.c:23 Breakpoint 5 at 0x3b: file demo.c, line 23. (sdbug) c Continuing. Breakpoint 3, func_2 () at func2.c:4 4 int x=0,n=0; (sdbug) n 3 9 x += 5; (sdbug) bt #0 func_2 () at func2.c:9 #1 0x21 in main () at demo.c:13 (sdbug) c Continuing. Breakpoint 2, func_1 () at func1.s:14 14 mov r5, r4 (sdbug) disable 2 3 (sdbug) c Continuing. Breakpoint 5, main () at demo.c:23 23 while (i < 20) { (sdbug) p i $3 = 2 (sdbug) p j $4 = 100 (sdbug) c Continuing. Breakpoint 5, main () at demo.c:23 23 while (i < 20) { (sdbug) d 5 (sdbug) c Continuing. (SYSTEM HALT)................................................ PC=0x000e Total Instructions: 1384 Program exited normally. (sdbug) exit
9-18
Debugger
9.5.2 Example 2
This example illustrates the use of hardware-assisted debugging with the JTAG connection. The example program hw_dbg.s is shown in Appendix A, "Example Programs"
GNU gdb 4.18 Copyright 1998 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "--host=i686-pc-cygwin32 --target=sdsp-ZSP-elf". (sdbug) file a.out Reading symbols from a.out...done. (sdbug) jtag set_clk 2 0 0 (sdbug) target jtag Connected to the target JTAG. (sdbug) load .data: 0x 1 .. 0x 1 ... Loading .text: 0x 0 .. 0x ce ... Loading (sdbug) hw enable_ice (sdbug) hw insn_addr_brk 0x11 (sdbug) run Starting program: hardware_debug.out Connected to the target JTAG. .data: 0x 1 .. 0x 1 ... Loading .text: 0x 0 .. 0x ce ... Loading Before: r0:0000 r4:0000 r8:0000 r12:0000 r1:0000 r5:0000 r9:0000 r13:0000 r2:0000 r6:0000 r10:0000 r14:0000 r3:0000 r7:0000 r11:0000 r15:0000 %fmode:0000 %tc:0000 %imask:0000 %ip0:0000 %ip1:0000 %loop0:0000 %loop1:0000 %guard:0000 %hwflag:0004 %ireq:0060 c10:0000 c11:0000 %vitr:0000 c13:0000 amode:0000 %smode:0200 %pc:0000 %rpc:0000 %tpc:ffff %cb0_beg:0000 %cb1_beg:0000 %cb0_end:0000 %cb1_end:0000 %timer0:0000 %timer1:0000 %loop2:0000 %loop3:0000 c27:0000 c28:0000 c29:0000 %dei:0000 %ded:0000
Host: Waiting to scan out of target 6024 bits Host: Writing scan command Host: Scanned out of target 6024 bits ffff Successfully entered HW Debug mode ... (sdbug) i r 14 r14 0x00 (sdbug) i r 15
Example Debugging Sessions
9-19
r15 0x00 (sdbug) i r pc pc 0x1319 (sdbug) hw st_data_brk 0xab02 (sdbug) hw resume Host: Scanning into target 6024 bits Host: Finished scanning into target 6024 bits Host: Waiting to scan out of target 6024 bits Host: Writing scan command Host: Scanned out of target 6024 bits ffff (sdbug) i r 14 r14 0x44 (sdbug) i r 15 r15 0x00 (sdbug) i r pc pc 0x3048 (sdbug) hw resume Host: Scanning into target 6024 bits Host: Finished scanning into target 6024 bits Host: Waiting to scan out of target 6024 bits Host: Writing scan command Host: Scanned out of target 6024 bits ffff (sdbug) i r 14 r14 0x77 (sdbug) i r 15 r15 0x00 (sdbug) i r pc pc 0x4569 (sdbug) hw st_addr_brk 0x2000 (sdbug) hw resume Host: Scanning into target 6024 bits Host: Finished scanning into target 6024 bits Host: Waiting to scan out of target 6024 bits Host: Writing scan command Host: Scanned out of target 6024 bits ffff (sdbug) i r 14 r14 0x88 (sdbug) i r 15 r15 0x00 (sdbug) i r pc pc 0x4c76 (sdbug) hw st_addr_and_data_brk 0x2001 0xab01 (sdbug) hw resume Host: Scanning into target 6024 bits Host: Finished scanning into target 6024 bits Host: Waiting to scan out of target 6024 bits Host: Writing scan command Host: Scanned out of target 6024 bits ffff (sdbug) i r 14 r14 0xd13 (sdbug) i r 15 r15 0x22 (sdbug) i r pc
9-20
Debugger
pc (sdbug) quit
0x82130
Example Debugging Sessions
9-21
9-22
Debugger
Chapter 10 ZSP Integrated Development Environment (ZSP IDE)
Version 4.0 of SDK Tools features a new Graphical Interface Integrated Development Environment for ZSP software project management, referred to as ZSP IDE. ZSP IDE is a productivity-enhancing tool for users of ZSP Processors, allowing easy setup, build, and debug of ZSP software projects. This chapter will focus on managing project structure and building executable ZSP programs. The ZSP IDE Debugger chapter describes the graphical user interface for the debugger. Features of ZSP IDE -
* * * * * * *
Workspaces to organize projects and default settings ZSP Project Build Support - G2, G1/G2, ZSP400 Compatibility - Backward-compatible with Version 3.2 Projects. Windows and UNIX (planned) platforms Multiple Projects in same directory Build Output linked to Source File View Parallel Debug Manager
System Requirements - ZSP IDE requires PC/Windows 95/98/2000. Although unsupported at this time, the IDE will be available on Solaris platforms as well in the future. This section is organized as follows: ZSP IDE Overview, Workspace Overview, Project Overview, and detailed functional information.
ZSP SDK Software Development Kit
10-1
10.1 ZSP IDE Overview
ZSP IDE provides an integrated tool suite for ZSP software developers by managing projects, building code, and debuging for all ZSP processors and supported targets. The graphical user interface allows easy project setup for users with minimal familiarity with ZSP tools and hardware. Figure 10.1 ZSP IDE Tools Suite Implementation
10.1.1 Introduction to Workspaces and Projects
Figure 10.2 ZSP IDE Workspace
10.1.1.1 Project The basic element of each ZSP software project is an executable file. Each executable file is managed by ZSP IDE based on settings that are
10-2
ZSP Integrated Development Environment (ZSP IDE)
created within ZSP IDE and stored in a project file. Project settings include all information needed to build and debug an executable:
* * * * * *
10.1.1.2 Workspace
Target ZSP Architecture Compiler Settings Include and Archive File directories Assembler Settings Debugger Settings IDE Debugger Window Settings
A workspace may contains any grouping of projects with any combination of processor settings and debug targets. The workspace component of ZSP IDE allows maintenance of default settings for its component projects. 10.1.1.3 IDE Figure 10.3 ZSP IDE Main Window
The main window layout of ZSP IDE contains the main menu, toolbar, project tree, source file editing area and output/utility windows.
ZSP IDE Overview
10-3
All of the main functions of ZSP IDE are available through the main menu. The most commonly used functions from the main menu are also accessible throught the toolbar. The project tree displays the workspace and project structure, allows opening of source files for editing, and provides quick access to pertinent menu functions through popup menus. At the bottom of the ZSP IDE main screen is the output window which displays the output of build and compile commands. Additional tabs grouped with the output window in the lower section provide a basic operating system shell interface and an output window for postprocessing functions (such as object dump utility) or for custom commands. The shell tab allows operating system command line capability from within the IDE. The Utility Output tab displays output of utility commands available from within the IDE. The bottom part of the IDE shows status information. The current cursor location in the editor window is also reflected in this status area.
10.2 Working With Workspaces and Projects
10.2.1 Working With Workspaces
The purpose of a workspace is to organize and to provide default settings for a Project or group of Projects. New and existing Projects may be added to a workspace. A Project may belong to multiple workspaces. A set of default properties can be set for a workspace. Any new project added to the workspace will inherit the default settings of the workspace. These settings may later be altered by the user. When an existing project is added to a workspace, the user is given the option to either keep existing project settings or inherit the default settings of the workspace. The Workspace menu has sub-menus to open, close and save workspace files. It also has sub-menus to add new or existing projects to a workspace. You can also delete projects from a workspace. A history of the previous workspaces visited is also available to quickly switch between workspaces. Only one workspace may be active at any time. Switching to a different workspace will close the existing workspace and the component projects. If a source file was altered and not yet saved, a
10-4
ZSP Integrated Development Environment (ZSP IDE)
warning is issued and the user is provided with an option to save changes before switching to a different workspace. Figure 10.4 Recent Workspaces List
10.2.1.1 Creating a new workspace A new workspace can be created by selecting Workspace>New from the IDE Main Menu. A dialog box is displayed to specify the filename for the new workspace. Figure 10.5 File Selection Dialog
The workspace filename will be taken from the Selection Entry in the Dialog Box. You may type or cut and paste the selected pathname directly into the Selection entry box and select the Create command button to create the new workspace, or you may navigate to a new directory from the currently selected one. The Files area shows the filtered contents of the selected directory when the Filter command button is selected. To limit file extensions shown in the file selection box,
Working With Workspaces and Projects
10-5
type the filter specification into the Filter Entry area and select the Filter button at the bottom of the Dialog Box. To change the directory, select from the directory selection box or type the directory into the Filter Entry area. To create a new directory, enter the desired path into the Selection entry area. The new directory will be created when the Create command button is selected. Workspace file names will always be specified by the filename extension ".ws". This is not modifiable. If another extension or no extension is specified, then the .ws extension will be created for the base filename entered. Note: 10.2.1.2 Open a Workspace An existing workspace can be opened using the same procedure as described in the previous section. 10.2.1.3 Save a Workspace Select Save from Workspace menu to save the current workspace. Select Save As from the Workspace menu to display the file selection dialog box to save a workspace with a different name or in a different directory. The new workspace becomes the current session after executing "Workspace -> Save As". 10.2.1.4 Add Projects to a Workspace To add new or existing projects to a workspace, select "Add Project" from the Workspace menu. The file selection dialog for projects is similar to that used for creating workspaces. The default filename extension for project files is ".pjt". Filenames may not contain space characters.
10-6
ZSP Integrated Development Environment (ZSP IDE)
It is also possible to add multiple projects to a workspace without closing the dialog box by selecting the Create command button for each project to be added. When all projects have been added, select Done to close the dialog box. 10.2.1.5 Delete a Project from a Workspace Select the project to be deleted from the workspace in the project explorer window then select Workspace->Remove Project. 10.2.1.6 Close a Workspace To close a workspace select Workspace->Close from the Workspace menu. Before closing a workspace, the user is prompted to save any unsaved files.
10.2.2 Working With Projects
A project is a container for source files, object files, executable files, build settings and debugger settings. Each project's settings are stored in a file with a .pjt extension. It is not necessary for the constituent files to be resident in the same directory as the project. The project can be moved as long as the paths to the source files are correct. Source files, header files, libraries and object modules can be shared across multiple projects. Multiple project files may exist in the same directory. The Project menu has sub-menus to open, close and save project files, and a sub-menu to add new or existing files to a project. You can also
Working With Workspaces and Projects
10-7
delete files from a project. A history of projects recently visited is available to quickly move between projects. Only one project can be active at any time. Switching to a different project will close the existing project. If a source file was altered, a warning is issued and the user is provided with an option to save changes before switching to a different project. Figure 10.6 Project Menu
10.2.2.1 Creating a New Project To create a new project within a workspace, you may select either from the main menu Workspace>Add Project>New Project or from the Project Tree popup menu over the active workspace node Add Project> New Project. A dialog box similar to that described for workspaces will be displayed and you may create the new project using the same methods. 10.2.2.2 Opening an Existing Project A Project can be opened by the following options Step 1. Step 2. Step 3. Project -> Open. The file selection dialog is displayed. One can browse to the appropriate directory and specify the project file (.pjt file) to be opened. Click OK
This will open the selected project. All associated component source, header, and object files will be shown in the project explorer pane.
10-8
ZSP Integrated Development Environment (ZSP IDE)
10.2.2.3 Saving a Project To save a project, select Save from the Project menu. To save a project to a new project file name, select Save As from the Project Menu. A dialog box is displayed to save the project with a different name or in a different directory. The new name is immediately reflected in the project explorer window and the new project becomes active. 10.2.2.4 Add Files to a Project To add new or existing files to a workspace, select "Add File" from the Project menu. The file selection dialog for files is similar to that used for creating projects. There is no default filename extension for files. The initial filter in the file selection dialog suggests source files. Edit the filter specification in the filter entry to display listings of files with alternate extensions. It is also possible to add multiple files to a project without closing the dialog box by selecting the Create command button for each file to be added. When all files have been added, select Done to close the dialog box. 10.2.2.5 Delete Files from project To delete a file from a project, use the popup menu over the file you would like to remove to select "Remove From Project". You may also select the file to be deleted from the project explorer window then select Project->Remove Files from the main menu. 10.2.2.6 Close a project To close a project select Project->Close from the Project menu. Before closing project the user is prompted to save any unsaved files.
10.3 Project Settings
Selecting Build->Settings or Debug->Settings from the main menu invokes the display of the Settings Dialog. If a workspace node is
Project Settings
10-9
selected in the project tree then the Settings Dialog will reflect the default settings for the workspace. The Settings Dialog contains a tabbed notebook view that contains all of the settings for a project, including settings for the ZSP compiler, assembler, linker, debugger, and GUI debugger preferences. These tabs are described below. You may page between the various tabs on the Settings Dialog and make changes. When the changes are complete for all of the tabs, select "Save and Exit" to save the settings to the project file and close the Dialog Box. Select "Exit without Saving" to discard the changes.
10.3.1 Build methodology and Project Tree Structure
The ZSP IDE project tree partitions project files into "folders" based on filename extensions. Source files which have extension of ".c" for C sources are added to the "C Source Files" folder. Source files which have a ".S" extension are assembly sources that require C preprocessing while a ".s" extension indicates an assembly source file which does not require preprocessing. Both ".S" and ".s" are inserted into the IDE Project Tree in "Assembly Source Files" folder. Include files which have extensions of ".h" or ".inc" will be added to the project tree "Include Files" folder. Additionally, when a file with a ".h" or ".inc" extension is added to the project, ZSP IDE will provide a prompt allowing the directory containing the files to the Include Directories list. Files with any other extension than those described here are inserted into the project in the "Other Files" folder and will not be part of the build process. The ZSP IDE invokes the appropriate ZSP compiler (SDCC ZDCC ZDXCC) based on the processor type selected in the Settings dialog. The ZSP compiler invokes each of the component processes that complete the build process. Options may be specified to direct the behavior or the compiler, assembler, and linker. These are specified in the Settings panel.
10.3.2 Compiler/Assembler Settings
The Compiler Settings tab is the primary control for each project. The processor architecture selected in the Compiler Settings tab controls the entire set of underlying command line tools and utilities. The three available architecture choices are
10-10
ZSP Integrated Development Environment (ZSP IDE)
* * *
G2 - This option selects the ZSP G2 architecture. ZSP400 - This option selects the ZSP400 architecture. G1G2 - This option is provided to enable building ZSP400 code for processors based on ZSP G2 architecture.
ZSP400 is the first generation ZSP architecture. This setting will work for all ASSPs based on this core (example LSI402ZX, LSI403Z, LSI403LP). ZSPG2 is the next generation architecture in the ZSP roadmap. It has many new instructions, new resources and a bigger address range. It is assembly compatible with the ZSP400. At this time there is a dual mac core called ZSP500 that is being designed based on the ZSPG2 architecture. It supports a 24-bit address range and is a 4 issue machine. The simulators in the toolchain support the ZSP500 in a cycle accurate and instruction accurate modes. Refer to the ZSP400 and ZSPG2 manuals for more information. Select G2 to compile for ZSP500 or G1/G2 to compile ZSP400 source code for G2.
Project Settings
10-11
Figure 10.7
Compiler Settings
Figure 10.8
Assembler Settings
The following table describes the other options that control the Compiler and Assembler.
10-12
ZSP Integrated Development Environment (ZSP IDE)
Table 10.1
Compiler/Assembler Options
Description This option instructs the compiler to produces debugging information for source-level debugging. This option instructs the compiler to print the commands executed in stages of compilation, and to print the version number of the tools before compilation. This option instructs the compiler to produce optimized code. Select optimization level 0-3. See the compiler section of this document for more details regarding optimization levels and the impact of optimizaton on debugging capabilities. This option supresses back-end optimization that is otherwise automatically performed on compiler-generated assembly code. This option will tell the compiler to use register-based calls (long calls). These calls can be optimized where possible if back-end optimization is enabled. The large data model has no requirements on the size or placement of the data and bss sections. This option specifies any compiler options that do not have a check box in the Compiler/Assembler options tab. Separate multiple options with spaces. This option instructs the compiler to compile and assemble the source files and produces object file(s) only (no linking is performed). This option instructs the compiler to stop after compilation and produces assembly code files for each C source file specified. This option stops compilation after the preprocessing stage and redirects the preprocessed output to standard output. This option instructs the compiler to compile all sources and link objects into the executable file specified in the Executable File Name entry. Specify the name of the executable file you want here.
Option (Command Line Equivalent) Produce debugging information (-g) Print stages of compilation (-v)
Optimization (-O number)
No assembly optimization (-mno_sdopt)
Use Long calls (-mlong_call)
Use Large Data Model (-mlarge_data) Additional compiler options Text Box (option)
Output Options
Create object files (-c)
Create assembly files (-s)
Preprocess files (-E)
Create executable (-o)
Executable File Name
Project Settings
10-13
Table 10.1
Compiler/Assembler Options
Description This option directs the compiler not to search the standard system directories for header and include files. Include Directories is a list of directories that the compiler will search for header and include files. This option forces the compiler to not use the standard system startup files or libraries during linking. This option suppresses warning messages. This option produces a listing file. The listing file includes high-level source information, assembly instruction information, and symbol information. Type a filename in the text box to save the listing to a file. The listing is sent to standard output if no filename is specified. This option specifies any compiler options that do not have a check box in the Compiler/Assembler options tab. Separate multiple options with spaces. This option includes debugging symbols in the object file to allow source-level debugging of assembly files. This option specifies any assembler options that do not have a check box in the Compiler/Assembler options tab. Separate multiple options with spaces.
Option (Command Line Equivalent) No standard includes (-nostdinc)
Include Directories (-I) No Standard Libraries (-nostdlib) Suppress warnings (-W) Listing option (-a)
Additional compiler options Text Box (option)
Produce debugging information (-dbg) Additional assembler options Text Box ( option)
The following table describes the options that control the linker.
10.3.3 Linker Settings
The Linker Settings window provides detailed control over link behavior. See the Linker section of this manual for more detail. a. Entry Point - The Entry Point directive to the linker specifies the starting address or label of the executable. The default is the label "__start" (provided in crt0.obj for C programs). For assembly programs you may specify the entry point to be any valid label or address, or you may accept the default which is the start of the ".text" section.
10-14
ZSP Integrated Development Environment (ZSP IDE)
b.
Locate Stack - The Locate Stack defines the __stack_start symbol that determines the starting address of the program stack pointer. Define Symbols - You may define other symbols with this option.
c.
d. Code Section (-Ttext) - You may specify the starting address for the ".text" section by entering a valid address in this entry box. e. Data Section (-Tdata) - You may specify the starting address for the initialized data section by entering a valid address in this entry box. f. BSS Section (-Tbss) - You may specify the starting address for the uninitialized data section by entering a valid address in this entry box.
g. Link Script - If you need more control over the locations of sections in you executable, you may specify a link script file in this entry. If you specify a relative pathname, it should be relative to your project directory. h. Additional Options - Specify any additional options for linking. i. j. Archive Files - Archive Files is a list of archive files to be linked with your project's object files to produce the executable. Object Files - Object Files is a list of object files to be linked with your project's object files to product the execuatable.
Project Settings
10-15
For archive and object files, you may invoke a file browser to select the files by selecting the appropriate "Add" command button. Likewise, remove a file from the list by selecting it with the mouse and then selecting the "Remove" command button. Table 10.2 Linker options
Description This option specifies a symbol for beginning execution of the program. The default entry point is __start. Enter the symbol in the text box. This entry defines the symbol __stack_start for the Linker to explicitly locate the program stack. Creates a symbol in the output file containing the absolute address specified by the expression. Enter the symbol and the expression in the text box, using the following syntax: symbol=expression. Note that spaces are not allowed next to the `=' sign. This entry specifies the starting address for the text segment of the output file. Default value is 0x0 This entry specifies the starting address of the data segment of the output file. Default value is 0x0. This entry specifies the starting address of the uninitialized data segment of the output file. Default value is 0x0. This entry specifies a filename to be used as a Linker Command File. Filename extension must not conflict with source / object file name extensions. Specifies external object files to be linked with the project's object files. Select Add button to select new object files from a File Selection Dialog box. To remove an object file from the list, select the entry with the mouse and then select Remove. Specifies external archive files to be linked with the project's object files. Select Add button to select new archive files from a File Selection Dialog box. To remove an archive file from the list, select the entry with the mouse and then select Remove. This entry specifies any linker options that do not have a check box in the Linker options tab. Separate multiple options with spaces.
Option (Command Line Equivalent) Entry Point (-e)
Locate Stack (__stack_start) Define symbols (-defsym)
Code Section(-Ttext) Data Section (-Tdata) Data Section (-Tbss)
Link Script
Object Files
Archive files List Box (-L)
Additional options
10-16
ZSP Integrated Development Environment (ZSP IDE)
10.4 ZSP IDE Detailed Description
10.4.1 Paned Window Controls
The IDE Main Window is divided into resizable sections by Paned Window Controls. IDE screen area displayed in the Paned Window may may be resized by dragging the handles of the paned window controls that separate the screen areas. Figure 10.9 Paned Window Handles
10.4.2 Project Tree
The Project Tree component of the ZSP IDE shows a hierarchical view of the files included in your projects and workspace. The Project Tree also provides the primary means of selecting the active project or workspace component. Figure 10.10 ZSP IDE Project Tree
ZSP IDE Detailed Description
10-17
Select the workspace node of the tree to customize default settings for your workspace. Default settings are applied to new projects when they are created within your workspace. Default settings may also be applied to existing projects when they are added to your workspace. To apply default settings to existing projects, select the checkbutton labeled "Use Workspace Settings" in the Preferences Window. To invoke the Preferences Window select Preferences from the View Menu. See Section 10.4.3.5, "View Menu," page 10-21 for details on the preferences window. Select a project or file from the tree to activate the project file as the Current Project. The Current Project is the project affected by Build and Debug operations. Select a file from the Project Tree to edit the file in the Edit Window. A popup menu is available for the workspace node of the project tree. To invoke the Workspace Popup Menu, click the right mouse button over the workspace node of the tree.
The Workspace Popup Menu shows the name of the workspace followed by shortcuts to workspace menu items from the main menu. A popup menu is available for a project node of the project tree in the same fashion as above.
10-18
ZSP Integrated Development Environment (ZSP IDE)
A popup menu is available for the filenode of the project tree in the same fashion as above.
10.4.3 Main Menu
The Main Menu provides access to major functions of ZSP IDE such as opening, closing, and maintaining workspaces, projects and files, as well as building and debugging projects 10.4.3.1 Operating the Main Menu Main menu items may be selected either by left-clicking with the mouse or by typing on the keyboard using menu accelerator keys (Underlined character in the menu name). To invoke the menus from the keyboard, depress the ALT key and the accelerator key for the Main Menu item concurrently. This will display the pull down subitem menu from which you can make further selections without using the ALT key. You may also use the Up, Down, Left, and Right arrow keys to navigate through the menus, terminating your choice with either the Enter key to confirm or the Escape key to cancel your selection. 10.4.3.2 Main Menu Functions The ZSP IDE Main Menu provides the following submenus:
* * * * * * * *
File Menu Edit Menu View Menu Project Menu Workspace Menu Build Menu Debug Menu Help Menu
ZSP IDE Detailed Description
10-19
10.4.3.3 File Menu The File Menu is used for operations on text files such as source files, include files, batch files, or any other text file. This menu is provided to open new or existing files and save and close active files. Figure 10.11 ZSP IDE File Menu
A file opened using the file menu does not automatically belong to the active project. A file needs to be explicitly added to a project as described in the section on Projects. A file may be opened and edited even if no workspace or project is active. 10.4.3.4 Edit Menu A simple editor is included in the IDE. The Edit Menu provides options that may be useful during editing. It is fairly intuitive to use and provides standard edit functionality like cut, copy, paste, indent, outdent, find, replace, select all, undo and redo. The Edit functions are applicable to a file that is being edited in the Edit Window. They are not applicable for projects, workspaces and directories and will result in errors if used for anything but File editing. Short cut keys are also available for common edit functions.
10-20
ZSP Integrated Development Environment (ZSP IDE)
Figure 10.12
ZSP IDE Edit Menu
10.4.3.5 View Menu The view menu is available to selectively display and customize ZSP IDE Screen components. Figure 10.13 ZSP IDE View Menu
View Preferences A user may set IDE enviromnent preferences by selecting View>Preferences. The preferences window offers options to alter editor settings in a tab labeled "Editor". Colors, Text style, line number and other preferences can be set in this window. The checkbutton labeled "Use workspace settings" controls the default project settings when a new project is created. If it is checked, then the project will be created with the default workspace settings, otherwise the project will be created with generic defaults. The checkbutton labeled "Use Relative Path" controls the type of path that is created within the workspace and projects. If it is not checked then absolute paths will be used for workspace components (projects and files, include directories, etc.) Otherwise relative paths are used. Relative path heirarchy begins with the workspace, (which is always an absolute
ZSP IDE Detailed Description
10-21
path). Projects are relative to the workspace. Files and other project component paths are relative to the project directory.
After finishing setting the preferences, click OK to save these settings. View Window View->Window provides the option to display or hide the Project Explorer set of tabs and the Output set of tabs. A check mark to the left of the item denotes if the window is active. The setting is toggled each time an item is selected. View Toolbar The Toolbar Buttons icons displayed in the toolbar at the top of the IDE window can be customized to a user's liking. There is a default that comes up as the standard toolbar. A user may select View->Toolbar->customize to customize the toolbar. When customize is selected a window titled "Customize Toolbar" pops up that shows the various options available for customizing. On clicking OK, the toolbar will be altered to display the customized settings. Select View->Toolbar->Customize to display the Customize Toolbar Window which allows selection of toolbar buttons to be displayed.
10-22
ZSP Integrated Development Environment (ZSP IDE)
Figure 10.14
Customize Toolbar
Switch back to the standard settings by selecting View->Toolbar>Standard. A check mark to the left of the item denotes if the selection is active. The setting is toggled each time an item is selected. 10.4.3.6 Project Menu The Project Menu allows projects to be created and maintained. Figure 10.15 ZSP IDE Project Menu
ZSP IDE Detailed Description
10-23
10.4.3.7 Workspace Menu The Workspace Menu allows Workspaces to be created and maintained Figure 10.16 ZSP IDE Workspace Menu
10.4.3.8 Build Menu The Build Menu invokes the ZSP IDE Build process and allows customization of Project Build Parameters. Figure 10.17 ZSP IDE Build Menu
Build Project Once a project is created and the constituent files added to it, the build settings which control the options with which the underlying tools (compiler, assembler, linker) are invoked can be set and the executable can be built. Build project will build the executable, using the options specified in the Project Settings window. This functionality is also available from the popup menu on the project tree when a project file is the selected node. When building the executable, build messages will be displayed on the output window in the Build / Compile Output tab if enabled.
10-24
ZSP Integrated Development Environment (ZSP IDE)
Figure 10.18
Build / Compile Output Window
The Build Output Window displays all the standard error or output of the process of building or compiling a project. The output can be saved by right clicking on the window. If errors in building are shown in the Build Output Window, you may easily display the source file and line containing the error in the Edit Window by double-clicking with the left mouse button on the line in the Build Output Window. A popup menu is available within the Build Output Window to save or clear the window contents. Figure 10.19 Build Output Window Popup Menu
Settings Select Settings to customize the parameters to be used for building your project. This functionality is also available from the popup menu on the project tree when the project file is the selected node. Compile Current Select "Compile Current" to compile the currently selected source file. The ZSP compiler is invoked with the -c option and an object file will be produced with the same base name as the input file and an extension of ".obj". This functionality is also available from the popup menu on the project tree when the source file is the selected node.
ZSP IDE Detailed Description
10-25
10.4.3.9 Debug Menu The Debug Menu provides configuration and control of Project Debugging. Figure 10.20 ZSP IDE Debug Menu
Use Default Target Select Use Default Target from the Debug Menu to ignore the Target Settings in the project file and use instead the default settings you have saved for your computer. Use Default Target is a system setting and is not a component of the project. The default target setting is stored in the ZSP Tools Program directory in a file named ZSPide.ini. Target Settings Select Target Settings from the Debug Menu to display the Debug Target Settings Panel Debug Settings displays the valid target types for the processor type that is specified in your project's Build Options. For ZSP400, valid Debug Targets are ZSIM, ZISIM, and Hardware Targets. For G2, valid Debug targets are software simulators ZSIM and ZISIM.
10-26
ZSP Integrated Development Environment (ZSP IDE)
Figure 10.21
Debug Settings
Figure 10.22
Debug Window Settings
ZSP IDE Detailed Description
10-27
Run Select Run to launch the ZSP IDE Debugger using the selected processor and debug target settings. Invoke PDM Select Invoke PDM from the Debug Menu to run the Parallel Debug Manager component of ZSP IDE. PDM allows concurrent debugging of projects. PDM is valid when a workspace is active and operates on all projects selected from within the current workspace. See Section 10.7, "Parallel Debug Manager," page 10-33 for more information on this feature. 10.4.3.10 Utilities Menu
objdump Select "objdump" from the Utilities Menu to invoke the objdump dialog box. The Object File Utility dialog box shows information about object files. The default object file is the compiler output file from the currently selected project. You may select another object file from a file selection dialog for processing by selecting the "Choose File" command button.
10-28
ZSP Integrated Development Environment (ZSP IDE)
Figure 10.23
Object File Utility
Figure 10.24
Utility Output Window Showing Disassembled Code
User Command Select User Command from the Utilities menu to display a dialog box that allows execution of a custom command to be executed.
10.4.4 Toolbar
The Toolbar provides easy access to commonly used functions of ZSP IDE.
ZSP IDE Detailed Description
10-29
Table 10.3
ZSP IDE Toolbar
The following functions are available through the toolbar. New File
Select the "New File" toolbar button to create a new text file in the IDE editor window. The new file is not automatically included in the current working project. If you wish the new file to be a project component, use the "Add File" option either from the main menu Project Menu or from the project tree popup menu over the selected project. Open File
Select the "Open File" toolbar button to open an existing text file in the IDE editor window. The opened file is not automatically included in the current working project. If you wish the opened file to be a project component, use the "Add File" option either from the main menu Project Menu or from the project tree popup menu over the selected project. Close
Select the "Close File" toolbar button to close the text file that is the being edited in the IDE edit window. Close All
Select the "Close All" toolbar button to close all of the text files that are the being edited in the IDE edit window. Save
10-30
ZSP Integrated Development Environment (ZSP IDE)
Select the "Save" toolbar button to save the file that is currently being edited in the editor window. Save All
Select the "Save All" toolbar button to save all of the files that are present in the editor window and that have been modified. Cut
Select the "Cut" toolbar button to cut selected text from the editor window. Copy
Select the "Copy" toolbar button to copy the selected text from the editor window into the clipboard buffer. Paste
Select the "Paste" toolbar button to paste the contents of the clipboard at the insertion point in the text file in the edit window. Find
Select the "Find" toolbar button to invoke the Find Dialog, which allows searching the current source file for the desired text. Settings
Select the "Settings" toolbar button to display the Settings window for the currently selected project or workspace.
ZSP IDE Detailed Description
10-31
Build
Select the "Build" toolbar button to invoke the build tools using the settings from the currently selected project Compile
Select the "Compile" toolbar button to compile the currently selected source file. Debug
Select the "Debug" toolbar button to invoke the GUI debugger for the currently selected project.
10.5 Shell Window
Figure 10.25 Shell Window
This is a window, where you can type dos commands
10-32
ZSP Integrated Development Environment (ZSP IDE)
10.6 Disassembly Window
Figure 10.26 Disassembly Window
The disassembly window shows disassembled code sections and is generated from the executable file. To populate the Disassembly Window, select Disassembly from the View Menu.
10.7 Parallel Debug Manager
When PDM starts, a configuration window is displayed from which you may select the projects from within your workspace that you would like to debug. Selected projects display a checkmark in the selection box. Figure 10.27 Parallel Debug Manager Setup Window
Select Run from the Debug menu choice to start debugging. The PDM window changes to debugging mode and ZSP IDE Debuggers are launched for each of the projects selected. Each debugger may be
Disassembly Window
10-33
controlled independently using its own controls, or all debuggers may execute the same commands as directed by the PDM Control Window. PDM Controls include command buttons from the Debug Execute menus and a command prompt and output window. Commands that are typed into the command prompt will have output displayed in the PDM output window for each of the projects being debugged. Figure 10.28 Parallel Debug Manager Control Window
10.8 Help Menu
10.9 Editor
The ZSP IDE Editor is a window where you can write your code. It allows basic editing functionality
10-34
ZSP Integrated Development Environment (ZSP IDE)
10.10 ZSP IDE File Formats
ZSP IDE produces a number of files when you create and compile a project or Workspace. These can be categorized as follows Table 10.4
Extension .c .S or .s .h .pjt .ws .exe Description C Source file Assembly source File Header File Project File Workspace File Executable file
ZSP IDE File Formats
10-35
10-36
ZSP Integrated Development Environment (ZSP IDE)
Chapter 11 ZSP IDE Debugger
This chapter describes how to use the ZSP IDE Debugger, a graphical debugging environment for developers using the ZSP family of Digital Signal Processor Cores. Version 4.0 of SDK Tools features a new Graphical Interface Integrated Development Environment for ZSP software project management, referred to in this document as ZSP IDE. The debug component of ZSP IDE is the focus of this chapter and is referred to as ZSP IDE Debugger. ZSP IDE Debugger is a menu-driven user interface to the ZSP Debugger. It provides a user-friendly graphical interface that allows navigation through your code while showing program and processor information for debugging purposes. The ZSP IDE Debugger allows setting breakpoints, examining registers and variables, watching source level variables, examining memory. Commands may be entered to be executed by the Command Line Debugger. The capability to automatically save your current debug settings and restore them at startup allows quick setup for each debugging session. The ZSP IDE Debugger is an integral component of the ZSP IDE executable (ZSPide.exe). The Debugger is configured and invoked from the IDE Debug Menu to operate on the IDE Current Project. The Debugger component of the IDE may be run independently from the IDE by using a separate executable (guidebug.exe). When running the Debugger in this way, a Project File may be loaded through the Debugger File Menu. Features of ZSP IDE Debugger -
*
Processor Support - ZSP G2 Architecture, ZSP400 Architecture, and G1/G2 (to use ZSP400 source code for processors based on ZSP G2 architecture.) Compatibility - Backwards-compatible with Version 3.2 Projects.
*
ZSP SDK Software Development Kit
11-1
* * * * * * * *
Windows and UNIX (planned) Debugger platforms Support for multiple targets Processor Register Windows - Operand, Control, Address Registers Displays cycle-accurate simulator information, code statistics, code profile, instruction grouping rules Concurrent Source and Disassembly level debugging 40-Bit Register display Multiple sessions may run concurrently Command-Line Debugger interface
Underlying Command Line Tools - Behind the ZSP IDE Debugger is a command line interface to a GNU Debugger (sdbug, zdbug, zdxbug) for the ZSP processor. Each currently supported debug target (ZSP Core) uses a separate configuration of the Command Line Debugger. Table 11.1
Target
Command Line Debugger Executables
Command Line Debugger
ZSP400 sdbug400.exe G2 G1G2 zdbug.exe zdxbug.exe
Target Interfaces Table 11.2 Debugger Targets
Simulator targets Cycle accurate simulator (zsim) Instruction level simulator (zisim) Hardware Targets Corelis PCMCIA based JTAG connector Corelis PCI based JTAG connector UART (Serial Port)
11-2
ZSP IDE Debugger
ZSP IDE Debugger supports the JTAG hardware target for ZSP400, UART (Serial Port) hardware target for ZSP400, ZISIM instructionaccurate simulator for ZSP400, G2, and G1G2, and ZSIM cycle-accurate simulator for ZSP400, G2, and G1G2.
11.1 GUI Debugger Overview
11.1.1 Main Window
The Main Window comprises a Title Bar, Menu Bar, Tool Bar(s), Status Area, and Debugging Window area in which Debugging Windows may be displayed.
11.1.2 Title Bar - Project File Name Display
When a project is loaded, the name of the project file is displayed in the Main Window Title Bar.
11.1.3 Window Area
Debugging Windows are displayed in the window area in the center of the Main Window. The Main Window configuration adds new Debugging Windows by splitting the available window size into panes that are resized by adjusting the handle on the separator between the windows. Alternatively, Debugging Windows may each be separated from the Main Window (see Section 11.1.7.3, "Top Level Window Presentation," page 11-8).
11.1.4 Status Area
The Status Area at the bottom of the Main Window shows general information throughout the debugging session, such as the target processor, debug target, executable file name, and debugging status.
11.1.5 Main Menu
The Main Menu provides access to major functions of the debugger such as controlling breakpoints, executing navigation commands, displaying Debugging Windows.
GUI Debugger Overview
11-3
11.1.5.1 Operating the Main Menu Main menu items may be selected either by left-clicking with the mouse or by typing on the keyboard using menu accelerator keys (Underlined character in the menu name). To invoke the menus from the keyboard, depress the ALT key and the accelerator key for the Main Menu item concurrently. This will display the pull down subitem menu from which you can make further selections without using the ALT key. You may also use the Up, Down, Left, and Right arrow keys to navigate through the menus, terminating your choice with either the Enter key to confirm or the Escape key to cancel your selection. 11.1.5.2 Controlling Debugging Windows Through the Main Menu Debugging Windows display program and/or debugging target information. Debugging Windows may be selected for viewing through the Main Menu checkbutton menu items. Debugging Window Menu Checkmarks - When a Debugging Window is displayed, the corresponding Main Menu item displays a checkmark in front of the menu text field Figure 11.1 Menu Checkmarks For Debugging Windows
11.1.6 Main Toolbars
Toolbars are available as menu shortcuts to provide access to commonly used debugging features. 11.1.6.1 Available toolbars Toolbars exist for the following areas:
*
Program navigation (Execute Menu shortcuts)
11-4
ZSP IDE Debugger
* *
Breakpoints (Breakpoint Menu shortcuts) Windows (Debugging Window menu shortcuts)
11.1.6.2 Invoking Toolbars Select Toolbars from the Tools Menu and select the desired toolbar by name to toggle the display of the toolbar below the menu in the Main Window. Figure 11.2 Tools Menu - Invoke Toolbars
11.1.6.3 Modifying Toolbar Appearance Toolbar Buttons may be viewed with text or icon annotation. To view the button annotation as text, select Preferences from the Tools Menu to display the Preferences Window then unselect the "use images" checkbutton. Figure 11.4 and Figure 11.5 illustrate the appearance of the toolbar for each of these annotation modes. Figure 11.3 Preferences - Use Images For Toolbar Buttons
Each Toolbar Button has a text description that is displayed when the mouse cursor is present on the button providing additional information regarding that button's functionality.
GUI Debugger Overview
11-5
Figure 11.4
Toolbar Buttons With Text Annotation
Figure 11.5
Toolbar Buttons With Image Annotation
11.1.7 Debugging Windows (General)
Debugging Windows comprise the following types (described in detail in later sections):
*
C/Assembly Program Windows - - - - - - - - - - Source Code Breakpoint List Debugging Symbols Call Stack Local Variables Global Variables Expression Watch ZSIM Statistics ZSIM Profile
*
Target system windows - - Disassembly Code Control Registers
11-6
ZSP IDE Debugger
- - - - -
Operand Registers Address Registers (G2) Memory ZSIM Grouping Rule ZSIM Pipeline
* *
Tools Preferences Command Line Interface
11.1.7.1 Debugging Window Operation Debugging Windows are displayed by selecting the appropriate menu item from the Main Menu or by selecting the appropriate button from the Window Toolbar. To remove the window from the display, invoke the menu item again to remove the checkmark, close the window by clicking on the "X" icon, or deselect the associated Toolbar Button. 11.1.7.2 Debugging Windows Paned Window Presentation Debugging Windows are presented by default in a Paned Window view as child windows within the Main Window. In this configuration, all windows appear at the same level, ie. no separate Debugging Windows. Each Debugging Window may be separated from the Paned Window ( see Section Debugging Window Top Level Preference - Page 9 and Section Changing Debugging Window View Mode - Page 9) Figure 11.6 Debugger Paned Window
Paned Window Operation - Windows displayed in the Paned Window may may be resized by dragging the handles of the paned window
GUI Debugger Overview
11-7
controls that separate the rows and columns of the Debugging Window area. Figure 11.7 Paned Window Handles
Resizing columns affects all windows in that column while resizing rows only modifies one window plus its vertical neighbor. Paned Window Configuration - The presentation of windows in the Paned Window may be configured in 1-4 columns by selecting Preferences from the Tools Menu and "Main Window Columns" from the Preferences Window Display Tab. To change the number of columns displayed during a session, Step 1. Set the desired number of columns in the preferences panel Step 2. Save the debugging session (File > Save > Session) Step 3. Reload the debugging session (File > Load > Session) Figure 11.8 Preferences - Set Main Window Columns
11.1.7.3 Top Level Window Presentation Top Level presentation of a Debugging Window displays that window as a separate Top Level window.
11-8
ZSP IDE Debugger
Figure 11.9
Top Level Debugging Window
Top Level focus control - Top Level Debugging Windows that are obscured by other graphics on the screen may be brought into focus for viewing by selecting the corresponding Window Button on the toolbar at the bottom of the Paned Window. Figure 11.10 Top Level Window Focus Control
Debugging Window Top Level Preference - New Debugging Windows may be automatically configured for Top Level presentation by selecting Preferences from the Tools Menu and then selecting the checkbox labeled "Separate New Windows" in the Display Tab of the Preferences Window. Figure 11.11 Preferences - Separate New Window
11.1.7.4 Changing Debugging Window View Mode Each of the Debugging Windows may be changed to and from Top Level or Paned Windows or may be closed by selecting the appropriate window icon at the upper right corner of that Debugging Window's submenu area.
GUI Debugger Overview
11-9
Click the left mouse button on the Window icon to separate the window into a Top Level Window. Click the left mouse button on the "X" icon to close the window. Figure 11.12 Display Controls for Paned Window
Click the left mouse button on the window icon to join the Top Level Window into the Paned Window. Click the left mouse button on the "X" icon to close the window. Figure 11.13 Display Controls for Top Level Window
11.1.7.5 Autoload Debugging Windows Preference When restarting a debugging session, the windows displayed in the previous session may be automatically displayed by selecting Preferences from the Tools Menu then selecting the "Autoload/save windows at entry/exit" checkbox from the Session Tab of the Preferences Window. Figure 11.14 Preferences - Autoload Windows
Display settings are saved as part of the project data when Autoload is selected. This includes all of the window preferences selections and all of the debugging windows that are open when the debugger is closed.
11-10
ZSP IDE Debugger
11.2 Detailed Descriptions
11.2.1 Main Menu
11.2.1.1 File Menu File operations available through the File Menu include:
* * * *
loading and saving debugging sessions loading an executable for debugging loading and saving memory images script recording and playback
11.2.1.2 Breakpoint Menu Breakpoints allow program execution to stop at specified code locations so that processor and program information may be examined during debugging. Each line of source or disassembly code may be specified as a Breakpoint. When a Breakpoint is enabled, program execution will be stopped when the line of code is scheduled as the next instruction. When a Breakpoint is disabled, program execution is not stopped at the line but continues past the breakpoint. Breakpoint Operations available through the Breakpoint Menu include:
* * * * *
toggling breakpoints at the currently selected source line enabling and disabling a breakpoint at the currently selected source line. disabling or deleting breakpoints at all except the currently selected line deleting, enabling, or disabling all breakpoints toggling display of the breakpoint listing window
Breakpoints are indicated in the Source and Disassembly Windows in the left-most column of the window. An Enabled Breakpoint is indicated by a red highlight in this area of the line. A Disabled Breakpoint is indicated by a gray highlight.
Detailed Descriptions
11-11
Figure 11.15
Breakpoint Menu
Current Selection Line - When setting a breakpoint from the breakpoint menu, the breakpoint will be set at the Current Selection Line. At the completion of each program navigation step (eg breakpoint reached, single step executed, etc) the Current Selection Line is the highlighted program line. The Current Selection Line for Breakpoint Operations may be set in either the Source Window or Disassembly Window. Left-click the mouse with the mouse pointer over the desired line and that line will become the Current Selection Line. Alternatively, you may use the up and down arrow keys to select the previous or next line of code as the Current Selection Line. When the Current Selection Line is selected with the mouse or keyboard, the address of the Current Selection Line is displayed in the status bar at the bottom of the Paned Window, the appropriate line/lines is/are highlighted in both the Source Code and Disassembly Windows, and subsequent Breakpoint Operations will be applied to that line. Figure 11.16 Source Code Window Current Selection Line
Breakpoint Toolbar (Menu alternative) - Each of the breakpoint functions except the listing is available from a toolbar that is displayed in the Main Window. To display the Breakpoint Toolbar select Toolbars from the Tools Menu and then select Breakpoint Management from the Toolbars cascade menu.
11-12
ZSP IDE Debugger
Toolbar settings are saved and restored for each debugging session when "auto load/save windows at entry/exit" is selected in Debugging Preferences. Breakpoint Menu - Toggle Set When a breakpoint is 'Toggle Set' by the "Toggle Set" menu choice, the debugger checks for the existence of a breakpoint at the current line. If a breakpoint exists, it is deleted. If a breakpoint does not exist, then one is created at the current line. Alternatives to Breakpoint Menu 'Toggle Set':
* * *
Source and Disassembly Window Popup Menus "Toggle Breakpoint" Source and Disassembly Window Breakpoint Area (left-most column of the window) left-click Keyboard Shortcut "T or t"
Example of Source Code Window breakpoint controls and displays Figure 11.17 Source Code Window Breakpoints
Toggle Enable When a breakpoint is 'Toggle Enabled' by the "Toggle Enable" menu choice, the debugger checks for the existence of a breakpoint at the current line. If a breakpoint does not exist, then one is created at the current line and enabled. If a breakpoint exists, the debugger checks for the enabled state of the breakpoint. If it is enabled then the breakpoint is set to disabled and vice-versa. Alternatives to Breakpoint Menu 'Toggle Enable'
* *
Source and Disassembly Window Popup menus "Toggle Breakpoint" Keyboard Shortcut "E or e"
Detailed Descriptions
11-13
Delete Except Selecting "Delete Except" from the Breakpoint Menu causes all breakpoints to be deleted except at the current line. If no breakpoint exists at the current line, then a breakpoint at the current line is created. Disable Except Selecting "Disable Except" from the Breakpoint Menu causes all breakpoints to be disabled except at the current line. If no breakpoint exists at the current line, then a breakpoint at the current line is created. Delete All Selecting "Delete All" from the Breakpoint Menu causes all breakpoints to be deleted. Enable All Selecting "Enable All" from the Breakpoint Menu causes all existing breakpoints to be enabled. Disable All Selecting "Disable All" from the Breakpoint Menu causes all existing breakpoints to be disabled. List Selecting "List" from the Breakpoint Menu displays a Debugging Window showing details of breakpoints currently set. Note: For details about the Breakpoint List Window, see Section , "Breakpoint List," page 11-22
11.2.1.3 Execute Menu The Execute Menu provides access to commonly used navigation features for debugging.
* * * * * *
Run Continue Stop Source Step Source Next Source Until
11-14
ZSP IDE Debugger
* * * * *
Source Finish Assembly Step Assembly Next Cycle Step Multiple Cycle Step Execute Menu
Figure 11.18
Alternative to execute menu for execute functions - Additional means of navigation are:
* * *
Program Navigation Toolbar Keyboard shortcut keys Popup menu on source and disassembly Debugging Windows
Program Navigation Toolbar Each of the execute functions is available from a toolbar that is invoked from the Tools Menu. To turn on the Program Navigation Toolbar, select:
Detailed Descriptions
11-15
Keyboard Shortcut Keys Keyboard shortcut keys allow single-keystroke navigation through program execution. Table 11.3
Key F2 R r F3 C c F4 S s F5 N n F6 A a F7 X x Ii Uu Oo Yy Mm
Keyboard Shortcuts
Action Run Continue Step Next Assembly Step Assembly Next finish Until stop Cycle-Step Multiple Cycle-Step
Popup Execution Functions Selecting a source or disassembly line and using the right-click popup menu allows run or continue to that line. Execute Menu Functions - Run Run causes the program to be run from the start. Continue Continue causes the program to be run from the current position. Step Step causes the program to advance from the current source position to the next source line for which debugging information exists. If the source file does not exist, the Disassembly Window will be invoked for navigation through the debug execution steps. If the current source is assembly
11-16
ZSP IDE Debugger
code then Step advances by one assembly instruction, stepping info function calls. Next Next causes the program to advance from the current source position to the next source line. If the current source position is a function call then the function is stepped over. Otherwise the behavior is the same as Step. If the current source is assembly code then Next advances by one assembly instruction, stepping over function calls. Assembly Step Assembly step advances program execution by an assembly-level instruction. Assembly step will follow calls to step into functions. Assembly Next Assembly next advances program execution by an assembly-level instruction. Assembly next will step over calls and will not step into functions. Finish Finish completes execution of a function and returns to the line following the function call. Until Until continues running until a source line past the current line in the current stack frame is reached. Stop Stop causes a dynamic breakpoint to be executed in a running program. Program execution is halted and current state of the program and processor is reflected in the Debugging Windows. Cycle-Step Cycle-step advances program execution by one processor clock cycle. Cycle-step is available for the ZSIM simulator target only. Depending on instruction grouping, more than one assembly instruction may be executed in a Cycle-Step. Multiple Cycle-Step Multiple Cycle-step advances program execution by a user defined number of processor clock cycles. Multiple Cycle-step is available for the ZSIM simulator target only.
Detailed Descriptions
11-17
11.2.1.4 Program View Menu The Program View Menu controls program-related windows. To display a window, select it from the menu. When the window is displayed, a checkmark is placed next to the window description. See Section 11.2.2.1, "C/Assembly Program Windows," page 11-19 for detailed window information. Figure 11.19 Program View Menu
11.2.1.5 Target View Menu The Target View Menu controls target hardware-related windows. To display a window, select it from the menu. When the window is displayed, a checkmark is placed next to the window description. See Section 11.2.2.2, "Target Windows," page 11-27 for detailed window information. Figure 11.20 Target View Menu
11.2.1.6 Tools Menu The Tools Menu provides customization of views for each project, access to a Command Line Debugger Interface, display of target settings, selection of toolbars to be displayed in the Main Window, and log file
11-18
ZSP IDE Debugger
display. See Section 11.2.2.3, "Tools Windows and Functions," page 11-33 for more information on the Tools Menu items. Figure 11.21 Tools Menu
11.2.1.7 Help Menu The Help Menu provides help.
11.2.2 Debugging Window Detailed Descriptions
11.2.2.1 C/Assembly Program Windows Available from the Program View menu or from the Window Toolbar, the Program Windows display data pertinent to execution of a program. Available Program Windows include:
* * * * * * * * * *
Source Code Window Breakpoint List Window Debugging Symbols Window Call Stack Window Local Variables Window Global Variables Window Expression Window Watch Window ZSIM Profile Window ZSIM Statistics Window
Source Code Window - The Source Code window displays the program source files for debugging. The location of the program source files are obtained from the debugging information in the loaded executable. Additional directories may be searched for source files by
Detailed Descriptions
11-19
using the Working Directories specification in the Project Settings dialog of the IDE. Accessing Source Code Window The Source Code Window is accessible through the Program View Menu by selecting "Source Code". Program execution tracking Tracking of program execution is visible through the Source and Disassembly Windows. The Current Line is highlighed as the next instruction to be executed. Source Code Window Display The Source Code Window is populated based on information reported from the Command Line Debugger. When the Source Code Window is created, all source files known to the Command Line Debugger are inserted into the file selection pulldown box when the Source Code Window is created. The content of the source files are read from their files and displayed in the Source Code Window either when you select the file for viewing from the file selection pulldown box or when program execution enters that source code file. Figure 11.22 Source Code Window
Source Code Window Syntax Highlighting If the project preferences indicate that syntax highlighting is desired, each file will be highlighted at creation. Source Code Window progress bar While source file loading or highlighting is in progress, a progress bar is displayed to inform the user of the status of the operation. If the source file is a Top Level window then the progress bar is also displayed as a Top Level window, otherwise the progress bar is displayed in the Main Window status area.
11-20
ZSP IDE Debugger
Figure 11.23
Progress Bar Window
Source Code Window Components The Source Code Window contains columns for breakpoint information, pipeline stage (ZSIM target only) line number, and source code text. The window submenu contains a source file listing drop-down box in the Source Code Window Menu. The source file drop-down box lists all of the source files known to the Command Line Debugger. Figure 11.24 Source Code Window (shown with Disassembly Window)
*
Source Code Window Breakpoint Area The breakpoint area shows enabled breakpoints in red, disabled breakpoints in gray and the current line is indicated by an ascii arrow. Source Code Window Line Highlighting The Source Code Window has two important items highlighted for user information, one being the Current Program Execution Line and the other being the User-Selected Line. - Source Code Window Current Execution Line Current Program Execution Line - indicated by a highlighted background on the code and line number areas. Source Code Window User-Selection Line User-Selection Line - indicated by a blue band over the line selected. The line may be selected by clicking the left mouse button on the desired line. The line may also be selected by using the keyboard up and down arrow keys. The source code filename and instruction address are displayed in the Main Window status bar when the user selects a line. If the 'Target View > Disassembly' Window is displayed when the user selects
*
-
Detailed Descriptions
11-21
a source code line, then the associated disassembly lines are also marked with the same color blue band and brought into view.
*
Source Code Window Popup Menu The popup menu for the source code or Disassembly Window is invoked by right-clicking the mouse over the code area. The popup menu allows you to toggle a breakpoint or breakpoint enable at the selected line, run from start to the selected line, or continue from the current execution point to the selected line. Run and continue to the selected line is implemented by saving the breakpoints, setting a break at the selected line and then executing run or continue as specified.
The source code window popup menu also allows a command-line debugger query to be performed using the word beneath the mouse pointer as the query expression. Figure 11.25 Example Source Code Popup Query Result
Breakpoint List - Selecting "Breakpoint -> List" from the Main Window causes a Debugging Window window to be displayed showing details of breakpoints currently set.
11-22
ZSP IDE Debugger
Figure 11.26
Breakpoint List Window
For each existing breakpoint, the breakpoint list shows:
* * * * *
source code file name source code file line number instruction address command line debugger's breakpoint identification number breakpoint enable state
Selecting a Breakpoint Line Left-click on a line in the breakpoint list to select that breakpoint as the current line for Breakpoint Operations. Actions on Selecting a Breakpoint Line When a breakpoint line is selected from the list, if the Source Code and/or Disassembly Windows are shown, the breakpoint line is highlighted and brought into focus in these windows. Operations Available for a Selected Breakpoint Line Right-click on a line in the breakpoint list to display a popup menu of breakpoint operations that may be applied to the selected Breakpoint. Saving of Breakpoints Breakpoints are saved and restored with the project session when Autoload is selcted from the Preferences Window. Debugging Symbols Window - Debugging Symbols are available for browsing using the Debugging Symbols Window. Two types of information are presented, program data symbols and program instruction symbols.
Detailed Descriptions
11-23
Figure 11.27
Debugging Symbols Window
*
Program Data Symbols The Symbols Window lists variables that are global, indicates the source file in which they are defined and the data type associated with the variable. Program Instruction Symbols The Symbols Window lists instruction labels for the program being debugged and the associated addresses.
*
The Debugging Symbols Window is only populated when it is invoked, since it will not change within the debugging session. Call Stack - To display a program's Call Stack, select Call Stack from the Program View Menu. Figure 11.28 Call Stack Window
Call Stack Code Viewing To view the code associated with one of the stack levels displayed, select that line in the Stack Window and select the Show Code button. The Source and Disassembly Windows will display the associated code. Call Stack Details Popup The Show Detail on the Stack Window menu shows details in a popup window so that information exceeding the display area may be easily examined. The detailed information includes the Stack Level, Address,
11-24
ZSP IDE Debugger
Procedure (name and arguments), Source File name, Source File line number. Local Variables - To display local variables, select Local Variables from the Program View Menu. The Local Variables Window shows all variables that are in the local scope. Figure 11.29 Local Variables Window
Global Variables - A view of global variables is available from the Main Menu by selecting 'Program View > Globals'. The Global Variables Window shows all variables that are global in scope. Figure 11.30 Global Variables Window
Expression - To have the debugger evaluate and display a single expression at each display refresh, use the Evaluate Expression Window. To invoke the Evaluate Expression Window, select Evaluate Expression from the Program View Menu. Type the expression you would like evaluated into the entry area and expression will be evaluated and displayed after each execution step
Detailed Descriptions
11-25
Figure 11.31
.Expression Window
Watch - To have the debugger evaluate and display multiple expressions at each display refresh, use the Watch Expression Window. To invoke the Watch Expression Window, select Watch Expression from the Program View Menu. Add expressions to watch using the Add Watch button in the Watch Expression Window. Remove expressions from the Watch Expression Window by selecting the existing expression and selecting the Remove Watch button. Figure 11.32 Watch Expressions Window
ZSIM Target Windows - ZSIM Debugging windows are available when ZSIM is selected as the target in the IDE Debug>Setup window.
*
ZSIM Profile A view of the code execution profile is available for the ZSIM target by selecting Profile from the Program View Menu. The menubar of the Profile Window includes a checkbutton to turn function profiling off and on and a checkbutton to select incremental mode, which shows only the functions executed since the last navigational step. The Profile Window shows each function name that is available for profiling, the histogram, cumulative and calls information reported by ZSIM. A bargraph chart is displayed with data type selectable from a drop-down selection box.
11-26
ZSP IDE Debugger
Figure 11.33
ZSIM Profile Window
*
ZSIM Statistics A view of code execution statistics is available for the ZSIM target by selecting Statistics from the Program View Menu.
Figure 11.34
ZSIM Statistics Window
11.2.2.2 Target Windows Available from the Target View Menu or from the Window Toolbar, the Target Windows display data pertinent to the state of the processor after
Detailed Descriptions
11-27
each navigational step in the debug session. Available Target Windows include
* * * * * * *
Disassembly Code Window Control Registers Window Operand Registers Window Address Registers Window (G2 only) Memory Window ZSIM Pipeline Window ZSIM Grouping Rule Window
Disassembly Window - The Disassembly Window shows disassembled instructions from the target's program memory. The address range of the Disassembly Window includes all instructions in the current scope. As execution proceeds, the Disassembly Window is repopulated as necessary. The Disassembly Window comprises left to right, a Breakpoint column, pipeline stage column (for ZSIM target only), address column, and disassembled code. The next line to execute is indicated by an ASCIIstyled arrow in the breakpoint column. Figure 11.35 Disassembly Window
Register Window General Description Three types of register windows, Control Register Window, Operand Register Window, and Address Register Window (G2 Only) are available to display and modify the processor registers. These windows have similar functionality. Each item in a Register Window may be edited by
11-28
ZSP IDE Debugger
left-clicking in the item to set the input focus, typing in the desired value followed by depressing the enter key. The new value is sent to the Debugger when the enter key is pressed. The Register Window is then refreshed to validate the entry. Each item in the Register Window may be formatted independently of the other items by right-clicking on the item to invoke the popup format menu. Figure 11.36 Register Element Popup Format Menu
Register Windows each contain a subwindow menu that includes the following functions.
*
Format The Format Menu in a Register Window allows reformatting of data for all of the visible registers to one of the following formats: - - - - - Fixed Point (for 16, 32, or 40-bit numbers) Hexadecimal Integer Unsigned Integer ASCII Character Register Window Format Menu
Figure 11.37
*
Columns The Columns Menu in the Register Window allows arrangement of the individual registers in the Window into 1-8 columns.
Detailed Descriptions
11-29
Figure 11.38
Register Window Columns Menu
*
Configure The Configure Menu item in the Register Window allows selection of individual registers to be displayed in the window by selecting them from a list. Register Window Configure Menu
Figure 11.39
Control Registers - The Control Registers Window provides access to the target processor's control registers. Figure 11.40 Control Register Window - Standard Mode
In addition to the common Register View submenu items, the Control Register Window also provides examination and modification capabilities for individual bit fields within each of the Control Registers. The individual bit fields may be edited in the same manner as described in the general Register Window description above.
*
Bit Fields The Bit Fields checkbox menu item in the Control Register Submenu
11-30
ZSP IDE Debugger
Window turns on the display of individual bitfields for the visible control registers. Each of the Control Register and Bit Field entries displayed in the Control Register Window is labeled with a mnemonic abbreviations of the register name. The full name and bit position(s) if appropriate are displayed in a popup text box when you move the mouse pointer over the entry or label. Figure 11.41 Control Register Bitfield Entry Annotation
Figure 11.42
Control Register Window - Bitfield Mode
Operand Registers - Operand Registers Window provides access to the target processor's operand registers. Menu items in the operand register Window include Format, Columns, and Configure functionality described above in the general Register Window description.
Detailed Descriptions
11-31
Figure 11.43
Operand Register Window
Address Registers (G2) - Address Registers Window provides access to the target processor's address and index registers. Menu items in the operand register Window include Format, Columns, and Configure functionality described above in the general Register Window description. Figure 11.44 Address Register Window
Memory - The Memory Window provides access to the target processor's memory. Menu items in the memory Window include Format and Columns functionality described above in the general Register Window description. except that memory may displayed in up to 16 columns. Figure 11.45 Memory Window
Start address for the memory Window may be an address or debugging symbol. ZSIM Target Windows - ZSIM Debugging Windows are available when ZSIM is the current debugging target.
*
Grouping Rule Window
11-32
ZSP IDE Debugger
The Grouping Rule Window displays ZSIM instruction grouping information. The rule displayed applies to instructions currently in the grouping stage at the pipeline. Figure 11.46 ZSIM Grouping Rule Window
*
ZSIM Pipeline Window The ZSIM Pipeline Window displays ZSIM pipeline information.
Figure 11.47
ZSIM Pipeline Window
11.2.2.3 Tools Windows and Functions Preferences Window - The Preferences Window provides customization of your project session preferences Command Line Debugger Window - The Command Line Debugger Window provides direct access to the Command Line Debugger. Commands entered in the command entry box are passed to the Command Line Debugger and the response from each command is presented in the output window.
Detailed Descriptions
11-33
Figure 11.48
Command Line Window
11.2.2.4 Using Session Logging The Session Logging functionality of the ZSP IDE debugger captures communications with the underlying Command Line Debugger for informational purposes. To configure Session Logging, open the Preferences Window by Selecting "Preferences" from the Tools Menu. Figure 11.49 Preferences Window - Logging
Session Log Types - The Session Log may be disabled by selecting the radiobutton labeled "Disable logging" in the Preferences Window. This setting is recommended for the best speed performance of the debugging environment. The Session Log may be directed to a window by selecting the radiobutton labeled "Log to Window" in the Preferences Window. Logging to a window provides continuous non-interactive update throughout the debugging session. Logging to a window is faster than logging to a file. There is no permanant Session Log record when logging to a window. The Session Log may be directed to a file for a permanent Session Log record by selecting the radiobutton labeled "Log to file" in the
11-34
ZSP IDE Debugger
Preferences Window. When Session Logging is recording to a file, the Log File Name is appended to the Tools Menu (see Figure 11.50). To view the Log File, select the Log File from the Tools Menu. If you want to retain log files after your debugging session exits, select the checkbutton labeled "Keep Log Files" in the Preferences Window. Otherwise the logfile will be automatically deleted. Figure 11.50 Tools Menu - Session Log File
The name of the log file is generated automatically and contains the project file name and a number related to the logging start time. Selecting the Log File name from the Tools Menu invokes the Session Log Window. Figure 11.51 Session Log Window
Log Window Controls
* *
Refresh - When logging to a file, the refresh button reads the log file into the Log Window text area Clear - Clears the Log Window text area
Detailed Descriptions
11-35
*
Log Type Radiobuttons - Radiobuttons labeled "Disable Logging", "Log To Window", and "Log To File" have the same functionality as their counterparts in the Preferences Window. The presence of these radiobuttons allows logging to be easily reconfigured when in use. Purge Log File - Each time the logging mode changes to "Log to File" a new log file is created and the log file name is updated on the Tools Menu. The "Purge Log Files" button deletes all log files in your project directory (ie those with a .log extension).
*
11-36
ZSP IDE Debugger
Appendix A Example Programs
This appendix contains two example programs, demo.c and hw_dbg.s, that are referred to in previous chapters of this document. The first example is a program project that combines C and assembly-language modules. The second example is a program used in hardware-assisted debugging.
A.1
Example Program: demo.c
This example is a C program in the file demo.c. It calls another C function, func2, in the file func2.c. It also calls two assembly functions, func1 and func3, in the assembly file func1.s.
int func_1 (int *t); void func_2 (); int func_3 (); int t=500; main() { char ch = `A'; int i,j = 100,k; for (i=0; i< 2; i++) { func_2(); k = func_1 (&j); if (k) { j = func_3() + 100; } else { j = 100; }
ZSP SDK Software Development Kit
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
A-1
} while (i < 20) { k++; i++; } } Example Program: func2.c int t1; void func_2 () { int x=0,n=0; while(n < 20) { switch(n) { case 0: x += 5; n =1; break; case 1: x = x <<4; n = 4; break; case 17: x = x ^ 13; n = 20; break; default: x++; n++; break; } t1 = x; }
A-2
Example Programs
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
Example Program: funcl.s .segment "text" .globl _func_1 .walign 2 _func_1: /** PROLOGUE **/ mov stu r13, %rpc r13, r12, -1
/** END PROLOGUE **/ mov ld mov cmp bgt ld mov add st mov br L2: mov br L1: /** EPILOGUE **/ bitc nop add ldu mov add bits ret %imask, 15 r12, 1 r13, r12, 1 %rpc, r13 r12, -1 %imask, 15 r4, 0 L1 r5, r4, r6, r4, L2 r4, r6, r4, r4, r4, L1 r4 r5 500 r6 r5 100 r6 r5 1
/*
*t <= 500;
*/
/*
*t += 100;
*/
/** END EPILOGUE **/
Example Program: demo.c
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
A-3
.extern_t .globl _func_3 .walign 2 _func_3: /** PROLOGUE **/ mov stu r13, %rpc r13, r12, -1
/** END PROLOGUE **/ mov lda ld shll add add lda ld add br L3: /** EPILOGUE **/ bitc nop add ldu mov add bits ret %imask, 15 r12, 1 r13, r12, 1 %rpc, r13 r12, -1 %imask, 15 r5, r4, r4, r4, r4, r4, r6, r6, r4, L3 300 _t r4 1 r5 r5 _t r6 r6
/**
k=i+2*t
**/
/** END EPILOGUE **/
A-4
Example Programs
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
A.2 Example Program hw_dbg.s
This example illustrates hardware-assisted debugging. It consists of one assembly file, hw_dbg.s. .section ".text" .global __start __start: bits %smode, 6 mov r0, 0xab00 mov r1, 0xab01 mov r2, 0xab02 mov r3, 0xab03 mov r4, 0xab04 mov r5, 0xab05 mov r14, 0 mov r15, 0 nop nop nop nop nop add r14, 1 mov r13, 0x2000 mov r12, 0x2001 nop nop nop nop nop add r14, 1 st r0, r13 nop nop nop nop nop add r14, 1 st r1, r13 nop nop nop nop nop add r14, 1
Example Program hw_dbg.s
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
A-5
st nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop
r2, r13
r14, 1 r0, r13
r14, 1 r1, r13
r14, 1 r2, r13
r14, 1 r0, r13
r14, 1 r1, r13
r14, 1 r2, r13
A-6
Example Programs
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
add st nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop add
r14, 1 r0, r13
r14, 1 r1, r13
r14, 1 r2, r13
r15, 1 r0, r12
r15, 1 r1, r12
r15, 1 r2, r12
r15, 1
Example Program hw_dbg.s
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
A-7
st nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop add st nop nop nop nop nop
r0, r12
r15, 1 r1, r12
r15, 1 r2, r12
r15, 1 r0, r12
r15, 1 r1, r12
r15, 1 r2, r12
r15, 1 r0, r12
A-8
Example Programs
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
add st nop nop nop nop nop add st nop nop nop nop nop bitc halt
r15, 1 r1, r12
r15, 1 r2, r12
%smode, 6
Example Program hw_dbg.s
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
A-9
A-10
Example Programs
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
Appendix B ZSP400 Control Registers
The ZSP400 control registers are listed in Table B.1. Table B.1
Register Reference Number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
ZSP400 Control Registers
Control Register %fmode %tc %imask %ip0 %ip1 %loop0 %loop1 %guard %hwflag %ireq reserved reserved %vitr reserved %amode %smode
Register Description Functional Mode Register Timer Control Register Interrupt Mask Register Interrupt Priority Register 0 Interrupt Priority Register 1 Loop 0 Register Loop 1 Register Guard Bits for {r1 r0} and {r3 r2} Condition Codes Interrupt Request Register - - Viterbi Traceback Register - Addressing Mode Register System Mode Register
(Sheet 1 of 2)
ZSP SDK Software Development Kit
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
B-1
Table B.1
Register Reference Number 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
ZSP400 Control Registers (Cont.)
Control Register %pc %rpc %tpc %cb0_beg %cb1_beg %cb0_end %cb1_end %timer0 %timer1 %loop2 %loop3 reserved reserved reserved %dei %ded
Register Description Program Counter Return Program Counter Trap Return Program Counter Circular Buffer 0 Begin Address Circular Buffer 1 Begin Address Circular Buffer 0 End Address Circular Buffer 1 End Address Timer0 Timer1 Loop 2 Register Loop 3 Register - - - Device Emulation Instruction Register Device Emulation Data Register
(Sheet 2 of 2)
B-2
ZSP400 Control Registers
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
Appendix C ZSPG2 Control Registers
The G2 control registers are listed in Table C.1. Table C.1
Register Reference Number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
G2 Control Registers
Control Register %fmode %tc %imask %ip0 %ip1 %loop0 %loop1 %guard %hwflag %ireq %cb2_beg %cb2_end %vitr %shwflag %amode %smode
Register Description Functional Mode Register Timer Control Register Interrupt Mask Register Interrupt Priority Register 0 Interrupt Priority Register 1 Loop 0 Register Loop 1 Register Guard Bits for {r1 r0} and {r3 r2} Condition Codes Interrupt Request Register Circular buffer 2 Begin Address Circular buffer 2 Begin Address Viterbi Traceback Register Sticky Condition Codes Address Mode Register System Mode Register
(Sheet 1 of 2)
ZSP SDK Software Development Kit
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
C-1
Table C.1
Register Reference Number 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
G2 Control Registers (Cont.)
Control Register %pc %rpc %tpc %cb0_beg %cb1_beg %cb0_end %cb1_end %timer0 %timer1 %loop2 %loop3 %cb3_beg %cb3_end reserved %dei %ded
Register Description Program Counter Return Program Counter Trap Return Program Counter Circular Buffer 0 Begin Address Circular Buffer 1 Begin Address Circular Buffer 0 End Address Circular Buffer 1 End Address Timer0 Timer1 Loop 2Register Loop 3 Register Circular Buffer 3 Begin Address Circular Buffer 3 End Address - Device Emulation Instruction Register Device Emulation Data Register
(Sheet 2 of 2)
C-2
ZSPG2 Control Registers
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
Appendix D L-Intrinsic Functions
This appendix describes the Long Intrinsic functions (L-Intrinsics) that were included in Version 1.0 of the SDK compiler and that are currently supported for backward compatibility. The L-Intrinsics are no longer implemented within the compiler itself, but rather with a header file, dsp.h. Note that although the L-Intrinsics are supported, you should develop new code using the N-Intrinsics, described in Chapter 3, "C Cross Compiler," Section 3.5, "N-Intrinsics," page 3-16. To use the L-Intrinsic functions, add the following line to all your C files: #include The compiler implements the L-Intrinsic functions using the assembly instructions shown in Table D.1. Table D.1 Long Intrinsic Functions
Underlying Instruction mul.a mac.a macn.a mac2.a mul.b mac.b macn.b mac2.b
Intrinsic Function L_mula L_maca L_macna L_mac2a L_mulb L_macb L_macnb L_mac2b
The long argument for the L_maca, L_macb, L_macna, L_macnb, L_mac2a, and L_mac2b intrinsic functions is copied to the appropriate accumulator register, which is {r0,r1} for the .a versions and {r2, r3} for the .b versions.
ZSP SDK Software Development Kit
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
D-1
The compiler generates code to copy the arguments to the proper accumulator registers, if required. Eliminating the steps required in copying the arguments minimizes execution time. Copying the arguments is not required if:
*
The long argument already exists in the appropriate accumulator (for example, if you call L_maca with a variable declared as type accum_a).
Execution time can also be minimized by not requiring the result to be copied to its destination. Copying the result is not required if:
*
The destination for the intrinsic function's result is already the target for the instruction used to implement the intrinsic function (for example, if L_maca returns a value to a variable declared as type accum_a)
For example, the following code is legal: accum_b b; int x,y; ... b = L_maca(b,x,y); However, it is more efficient to use: b = L_macb(b,x,y); In the first case (b = L_maca(b,x,y)), two copies are required--one to move {r3 r2} to {r1 r0} for the argument, and another to move {r3 r2} to {r1 r0} to the destination. The second case (b = L_macb(b,x,y)) requires no extra copies. Note that a call to an L_*a function clobbers any variable declared with an accum_a, and a call to an L_*b function clobbers any variable declared with an accum_b. In the following example, the value of variable a is equivalent to b after the L_maca function call: accum_a a; accum_b b; int x,y; a = 0; ... b = L_maca(b,x,y);
D-2
L-Intrinsic Functions
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
Note:
It is not guaranteed that a will have the same value as b in future versions of the SDK compiler.
This function returns a 32-bit result of the multiplication of a 16-bit variable var1 with a 16-bit variable var2, with one shift left. This function returns a 32-bit result of the multiplication of a 16-bit variable var1 with a 16-bit variable var2, with one shift left. This function multiplies the 16-bit variable var1 by the 16-bit variable var2 and shifts the result left by 1. This 32-bit result is added to the 32-bit variable var3 with saturation and returns the 32-bit result. This function multiplies the 16-bit variable var1 by the 16-bit variable var2 and shifts the result left by 1. This 32-bit result is added to the 32 bit variable var3 with saturation and returns the 32-bit result. This function multiplies the 16-bit variable var1 by the 16-bit variable var2 and shifts the result left by 1. This 32-bit result is subtracted by the 32-bit variable var3 with saturation and returns the 32-bit result. This function multiplies the 16-bit variable var1 by the 16-bit variable var2 and shifts the result left by 1. This 32-bit result is subtracted by the 32-bit variable var3 with saturation and returns the 32-bit result. The lower 16 bits of the variable var1 is multiplied with the lower 16 bits of the variable var2. The higher 16 bits of the variable var1 is multiplied with the higher 16 bits of variable var2, and the two 32-bit results are added to the variable var3, which is the return value.
Long L_mula (int var1, int var2)
Long L_mulb (int var1, int var2)
Long L_maca (long var3, int var1, int var2)
Long L_macb (long var3, int var1, int var2)
Long L_macna (long var3, int var1, int var2
Long L_macnb (long var3, int var1, int var2)
Long L_mac2a (long var3, long var1, long var2)
D-3
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
Long L_mac2b (long var3, long var1, long var2)
The lower 16 bits of the variable var1 is multiplied with the lower 16 bits of the variable var2. The higher 16 bits of the variable var1 is multiplied with the higher 16 bits of variable var2, and the two 32-bit results are added to the variable var3, which is the return value. This function produces the number of left shifts required to normalize a 32-bit variable var1. The number is a 32-bit result. This function produces the number of left shifts required to normalize a 16-bit variable var1. The number is a 16-bit result. This function returns a 32-bit result, where the high-order 16 bits is the input 16-bit variable var1, and the low-order 16 bits are zeroed. This function returns a 16-bit result which is the high-order 16 bits of the 32-bit input. This function returns a 32-bit result which is the absolute value of the 32-bit variable var1. Note that abs (0x8000) returns 0x7FFF. This function returns a 16-bit result which is the absolute value of the 16-bit variable var1. Note that abs.s (0x8000) returns 0x7FFF. This function returns a 16-bit result. The result is obtained by rounding the lower 16 bits of the 32-bit input number and storing it in the higher 16 bits with saturation. This value is then shifted right by 16 bits to obtain the result.
Long norm_l (long var1)
int norm_s (int var1)
Long L_deposit_h (int var1)
int extract_h (long)
Long L_abs (long var1)
int abs_s (int var1)
int round (long)
D-4
L-Intrinsic Functions
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
Appendix E Signal Processing Library
The library, libalg.a, contains some basic functionality commonly used in signal processing. The interface to libalg.a is contained in alg.h, which can be accessed with: #include To use this library, it must be linked in with a -lalg switch on the link line.
ZSP SDK Software Development Kit
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
E-1
E.1
API Specification Auto-correlation Library Function on G2
Auto-correlation
Synopsis void lib_autocorr(*Struct_AUTOCOR)
*Struct_AUTOCOR Pointer to the Auto-correlation Structure
E.1.1
Input The input variables that are to be passed through the AUTOCOR structure:
short DataSize short InputData Length of the input data Input data array of size Datasize*2
short NumberOfLags Number of auto-correlation lags needed short Scale Factor to use in scaling the partial products
Return Value None Output The output is returned as a field in the AUTOCOR structure
short AutoCorrData Array to hold the Auto-correlation values
Description This function implements the auto-correlation of the input data (InputData) and stores the computed correlation lags in an array (AutoCorrData). The number of correlation lags are specified by NumberOfLags. As the number of lags are small, a direct sum-of-product algorithm is used for computing the correlation values.
E-2
Signal Processing Library
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
E.2
API Specification for Convolutional Encoder Library Function on G2
Convolutional Encoder
Synopsis void lib_convEnc_k9r2(short *inpw, short *outpw, short Nwords) Input
Short *inpw Short Nwords Pointer to input data (packed, 16-bit array) Size of input array
E.2.1
Return None Output
Short *outpw Pointer to output data (packed, 16-bit array)
Description This function implements a Convolutional encoder with generating polynomial, G0 = 1 + D2 + D3 + D4 + D8 (octal 561) G1 = 1 + D1 + D2 + D3 + D5 + D7 + D8 (octal 753) and with a constraint length of K=9 and rate of R=1/2. It employs Block-XOR technique, along with LUT-based sorting and operates on packed words containing input data bits. Dependencies/Assumptions This encoder always starts from the zero state. Assumes that the input data bits are packed into an array of 16-bit words, in a "right-MSB" format, that is, in each word, the LSB has the oldest
API Specification for Convolutional Encoder Library Function on G2
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
E-3
data. In the final word, if there are fewer than 16 data bits, the MSB part may be filled with zero bits but not essential. The output encoded bits are available packed into 16-bit words in the same "right-MSB" format. The output array size is twice that of the input array, and any extra bits in the final output word may be ignored.
E-4
Signal Processing Library
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
E.3
E.3.1
API Specification for 16bit CRC Library Function on G2
CRC 16bit
Synopsis short lib_crc16(short *inpw, short Nwords) Input
Short *inpw Short Nwords Pointer to input data (packed, 16-bit array) Size of input for which CRC is needed
Output
Short crc16 Computed checksum (16-bit scalar)
Description This function implements CRC-16 bit checksum calculation, based on the Generating Polynomial P(D) = D(16) + D(12) + D(5) + 1 (decimal 69,665). Dependencies/Assumptions Assumes that the input bits are packed into an array of 16-bit words, in a "right-MSB" format, that is, in each word, the LSB has the oldest data. In the final input word, if there are fewer than 16 data bits, the MSB part may be filled with zero bits but not essential. The output encoded bits are available packed into one 16-bit word in the same "right-MSB" format.
API Specification for 16bit CRC Library Function on G2
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
E-5
E.4
E.4.1
API Specification for 8bit CRC Library Function on G2
CRC 8bit
Synopsis short lib_crc8(short *inpw, short Nwords) Input
Short *inpw Short Nwords Pointer to input data (packed, 16-bit array) Size of input for which CRC is needed
Output
Short crc8 Computed checksum (16-bit scalar)
Description This function implements CRC-8 bit checksum calculation, based on the Generating Polynomial D(8) + D(7) +D(4) + D(3) + D + 1 (decimal 411). Dependencies/Assumptions Assumes that the input data bits are packed into an array of 16-bit words, in a "right-MSB" format, that is, in each word, the LSB has the oldest data. In the final input word, if there are fewer than 16 data bits, the MSB part may be filled with zero bits but not essential. The output encoded bits are available packed into one 16-bit word in the same "right-MSB" format.
E-6
Signal Processing Library
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
E.5
API Specification for 32 bit Division Library Function on G2
32 bit Division
Synopsis Result32 lib_div32( Num32, Den32 Input
Int Num32 Int Den32 32 bit positive integer 32 bit positive integer
E.5.1
)
Return
Int Result32 Q31 Fractional number
Description Performs a 32 bit fractional division between two 32 bit positive integers Result32 = Num32/Den32 The technique is a 32 bit implementation of the 16 bit divide step instruction "diva"
API Specification for 32 bit Division Library Function on G2
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
E-7
E.6
E.6.1
API Specification for IIR Library Function on G2
IIR
Synopsis
void lib_IIR(short *indata, short *coef, short *state, short N)
Input
Short *indata Short *coef Short *state Short N Pointer to input data. Coefficient vector. Intermediate state of the filter. Length of the input data vector.
Return None Output Output is returned in the "indata" input data vector. Description This function implements an in-place Infinite Impulse Response (IIR) filter. Dependencies/Assumptions The input data is assumed to be in Q1.15 format. The number of taps in the filter "T" must be a multiple of 2. Coefficients are stored as -a1/2, -a2/2, b1/2, b2/2, ..., b0/2. Input data is stored 0, In(0), In(1), ..., In(N).
E-8
Signal Processing Library
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
E.7
E.7.1
API Specification for IIR Biquad Library Function on G2
IIR Biquad
Synopsis
void lib_IIRBIQ(short *indata, short *coef, short *state, short N-1)
Input
Short *indata Short *coef Short *state Short N-1 Pointer to input data. Coefficient vector. Intermediate state of the filter. Length of the input data vector.
Return None Output Output is returned in the "indata" input data vector. Description This function implements an in-place Biquad Infinite Impulse Response (IIR) filter. Dependencies/Assumptions The input data is assumed to be in Q1.15 format. The number of taps in the filter "T" must be a multiple of 2. Coefficients are stored as -a11/2, a21/2, b11/2, b21/2 -a21/2, a22/2, b21/2, b22/2. Input data is stored 0, In(0), In(1), ..., In(N).
API Specification for IIR Biquad Library Function on G2
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
E-9
E.8
API Specification for Inverse Square Root Library Function on G2
Inverse Square Root
Synopsis Xout lib_invsqrt( Xi ) Input Short Xi (1.99999) Return short Xout < 0x7fff (1.99999) Description Calculate the inverse square root of an input Xi. Xout = 1/sqrt( Xi ) Technique employs a look up table to obtain a first approximation to Xout. The approximation Xout is then used by following recursive algorithm to calculate a more precise value for Xout. Xout = (3/2)*Xout - (Xi * Xout^3)/2 Three iterations of the above algorithm are performed Q14 number in the range 0x1000 (0.25) < Xi Q14 number in the range 0x1000 (0.25) < Xi < 0x7fff
E.8.1
E-10
Signal Processing Library
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
E.9
API Specification for Synthesis Lattice Filter Library Function on G2
Synthesis Lattice Filter
Synopsis short lib_lattice(short *b, short n, short *k) Input
Short *b Short n Short *k Array of filter coefficients Number of data samples Array of filter coefficients
E.9.1
Output
Short f Result of forward synthesis
Description This function implements a Lattice filter. The lattice is a synthesis filter which calculates the following loop: f -= b[n - 1] * k[n - 1]; for (i = n - 2; i >= 0; i--) { f -= b[i] * k[i]; b[i + 1] = b[i] + (k[i] * f); { where "n" is the order for the filter, "k" and "b" are coefficients and "f" is the "forward result" The variables f, b[i],k[i] and k are in q15 format.
API Specification for Synthesis Lattice Filter Library Function on G2
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
E-11
E.10 API Specification for Real Block FIR Library Function on G2
E.10.1 Real Block FIR
Synopsis void lib_realblockfir(*FIR)
*RBF_CFG_Type Pointer to a configuration type structure
Input
int *x int *h int N int T Address of input array, length>=N. Address of coefficients, length>=T. Coefficients stored in reverse order h(T-1) ... h(0). Number input samples in x to filter. N must be multiple of 4. Number of filter taps (length of h). T must be multiple of 4 and T>=8.
Output
int *y int *delay_line int *delay_current Address of output array, length>=N Base address of delay line Ptr to current addr in delay line (oldest sample)
Description This function implements a real valued block FIR filter. The N samples of input array ("x") are filtered with T filter coefficients in array ("h"), and the result is stored in array ("y"). The input, output, and filter coefficients are 16-bits. The filter coefficients must be stored in reverse order h(T-1) ... h(0). A delay line is used to hold the history of input data and it is updated each time to contain the latest T samples and point to the oldest of them.
E-12
Signal Processing Library
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
Accumulations are 40 bits with bits 31-16 being the stored result, which will be saturated if SAT is enabled. Two taps for each of 4 output samples are computed every iteration of the inner loop.
API Specification for Real Block FIR Library Function on G2
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
E-13
E.11 API Specification for 256 point FFT Library Function on G2
E.11.1 256 point FFT
Synopsis void lib_FFT256(short *in_data, short *out_data, *twiddles) void lib_iFFT256(short *in_data, short *out_data, *twiddles) Input
Short *in_data Short *twiddles Pointer to input data Array of Twiddle factors
Return None Output
Short *out_data Computed FFT or iFFT values
Description This function implements a 256 point complex, Radix-2, decimation-intime Fast Fourier Transform (FFT) algorithm. Dependencies/Assumptions The input and output data are to be stored as Im,Re,Im,Re... and are in natural order. The input and output data is in Q.15 format. Twiddle factors have to be recalculated and stored in memory.
E-14
Signal Processing Library
Copyright (c) 1999-2002 by LSI Logic Corporation. All rights reserved.
Index
Symbols
__FUNC_EXIT_region_name 9-7 __FUNC_START_region_name 9-7
L
LD_LIBRARY_PATH 2-11 lib 2-12 libraries 2-12
A
Accessing Memory 9-13 accum_a 3-5 accum_b 3-5
M
mapfile 2-13 memory_download 9-4 memory_upload 9-4 -mempcr 9-2 mlong_call 3-2 mno_sdopt 3-2 mode registers 3-7
B
baud rate 9-7
C
C run time stack 3-10 Callee preserved registers 3-6, 3-7 caller saved registers 3-6 Cycle-step 9-13
N
-no_mempcr 9-2
P
Parameter registers 3-6, 3-7
D
Data Type 3-5
Q
q15 3-5
E
ELF 1-5
R
Register Usage 3-6 Return registers 3-7
G
GNU documentation 1-2
S
save-temps 3-4 SDBUG 9-1 sdcc 3-1, 3-28 sdopt 1-4, 3-3 SDSP_HOME 2-11 sdsp_install 2-10 serial Number 2-2 Stack Frame 3-11 Stack pointer 3-6, 3-7 structure passing 3-9
H
header files 2-5, 2-8, 2-12
I
include 2-12 install 2-2 Installation_Directory 2-3, 2-5, 2-6, 2-7, 2-8
J
JTAG 9-8 JTAG clock 9-8
U
UART Connection 9-7 User-specified Profiling 9-6
ZSP SDK Software Development Kit
IX-1
V
vold 2-10
W
www.gnu.org 1-2
Z
ZISIM target 9-3
IX-2
Index
Customer Feedback
We would appreciate your feedback on this document. Please copy the following page, add your comments, and fax it to us at the number shown. If appropriate, please also fax copies of any marked-up pages from this document. Important: Please include your name, phone number, fax number, and company address so that we may contact you directly for clarification or additional information.
Thank you for your help in improving the quality of our documents.
ZSP SDK Software Development Kit
Reader's Comments Fax your comments to: LSI Logic Corporation Technical Publications M/S E-198 Fax: 408.433.4333
Please tell us how you rate this document: ZSP SDK Software Development Kit. Place a check mark in the appropriate blank for each category.
Excellent Good Average Completeness of information Clarity of information Ease of finding information Technical content Usefulness of examples and illustrations Overall manual ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ Fair ____ ____ ____ ____ ____ ____ Poor ____ ____ ____ ____ ____ ____
What could we do to improve this document?
If you found errors in this document, please specify the error and page number. If appropriate, please fax a marked-up copy of the page(s).
Please complete the information below so that we may contact you directly for clarification or additional information. Name Telephone Title Department Company Name Street City, State, Zip Date Fax Mail Stop
Customer Feedback
You can find a current list of our U.S. distributors, international distributors, and sales offices and design resource centers on our web site at http://www.lsilogic.com/contacts/na_salesoffices.html


▲Up To Search▲   

 
Price & Availability of ZSP

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X